I am using "node.attributes" to retrieve all the attributes of a DOM node using JavaScript in IE.
It gives me additional attributes which are not specified in the source .In Firefox it gives only those which are specified in html source (which is expected).
is there any way to retrieve "only the attributes" of a DOM elements which are specified in its HTML source in IE?
Thanks in advance.
-Sourabh
The attributes have a specified property which is true if the attribute was specified in the HTML source or explicitly set by script.
Related
Is there a script attribute in HTML for JS, like the style attribute for CSS, I asked this because I'm using an IDE that highlights script attributes inside elements, so I thought it might exist, and if it does, how to use it ?
<element style="it exists, and i know how to use it" script="no clue">...</element>
HTML5, like previous HTML elements, does not have a script attribute but has a script element: https://www.w3.org/TR/html5/scripting-1.html#the-script-element. You can either put some script directly between <script> and </script> tags, or use the script element to refer to an external JavaScript file.
The JavaScript itself can then dynamically (e.g. on load) add event listeners to HTML elements that need to respond to specific events.
No, there is no 'script' attribute. The IDE is probably doing a match on the pattern, without regard to context.
Your IDE is simply highlighting any tag attribute. Try making up some gibberish, and you'll see that it's highlighted.
As the other answers state, no script attribute exists. From w3.org,
There are two types of scripts authors may attach to an HTML document:
Those that are executed one time when the document is loaded by the
user agent. Scripts that appear within a SCRIPT element are executed
when the document is loaded. For user agents that cannot or will not
handle scripts, authors may include alternate content via the NOSCRIPT
element.
Those that are executed every time a specific event occurs.
These scripts may be assigned to a number of elements via the
intrinsic event attributes.
No there is no standard attribute in HTML 5 called script.
But as previous answers listed, your IDE may highlighted this because it highlight any attribute, or script keyword for something else based on your file type.
Also note that while script is not a standard attribute in HTML 5 but this doesn't mean you can't use it, you can write your own custom attributes to any element to access it using javascript getAttribute
Every Node instance has a baseURI property.
Node instances of ELEMENT_NODE type maintain namespaceURI property.
What are the significance of these two properties for a browser to manage the nodes in DOM?
The namespaceURI is the namespace of the element. So for non-foreign elements in the HTML serialisation, that's http://www.w3.org/1999/xhtml.
The Base URL of a node is, in principal, akin to the <base> element in HTML. That element only sets the base URL for the document. But in XML, a base can be set on any element such that it applies to the xlink:href attributes of its descendent elements, via the xml:base attribute. The XML Base spec describes this. Again, in principal, this should apply to XHTML documents (properly served as application/xhtml+xml of course), for example <a> elements in the svg namespace. However, a quick test shows that in fact, while Firefox supports this correctly, Chrome and IE do not.
I want to add the manifest attribute during run-time, so the I can control when the Appcache will be downloaded.
Ex: When a user is logged into the application properly,
<html>
// page content
</html>
changes into:
<html manifest="myapp.manifest">
// page content
</html>
Is there anyway I can achieve this using javascript, jquery or anything? What I want to is to control when the Appcache will be downloaded conditionally.(I have already read about having another html inside an iFrame.)
According to the specification, changing the manifest attribute after the document loaded has no effect.
You can still access the html element and change the attribute value, via document.documentElement:
document.documentElement.setAttribute('manifest', 'myapp.manifest');
It just won't do anything.
You can use .attr():
Get the value of an attribute for the first element in the set of
matched elements or set one or more attributes for every matched
element.
$('html').attr('manifest','myapp.manifest');
Normal ways to add an attribute to an element can be used, e.g.
document.documentElement.setAttribute('manifest', 'foo.appcache');
(As #FelixKing points out in a comment, assigning to document.documentElement.manifest does not work, by the specs, since manifest is not defined in the DOM. I was first misled by Chrome’s behavior in this issue.)
However, this has no effect. HTML5 CR says: “The manifest attribute only has an effect during the early stages of document load. Changing the attribute dynamically thus has no effect (and thus, no DOM API is provided for this attribute).”
(Well, it has the effect of being there, so you could use the attribute in styling, retrieve the attribute value, etc. But nothing that would cause application cache operations.)
Try this:
document.documentElement.setAttribute('manifest', 'myapp.manifest');
From the docs:
document.documentElement
Returns the Element that is the root element of the document (for
example, the element for HTML documents).
Try this by jQuery.
$('html').attr('manifest', 'myapp.manifest');
It may not be possible to effectively add the manifest attribute, but it might be possible to remove it and by that you may achieve the same result.
To disable appcache, I use this:
window.console.warn('removing appcache');
window.document.documentElement.removeAttribute('manifest');
Please be carefull, this may not always work!
I'm creating a firefox extension and I want to get the HTML page elements
using javascript but the document.getElementsByTagName('*') is always giving me an xul objects array.
How can I get the HTML objects array ?
If you want to access the current tab's content from an extension then you need to use content.document.getElementsByTagName('*') etc.
According to a school assignment, only one property of the Document object can be dynamically changed after a Web page is rendered. Is it body or cookie?
You can manipulate the body contents, but can't assign to the body property. It's a readonly property. You can however set or get the cookies associated with the document. Reference: http://www.w3schools.com/htmldom/dom_obj_document.asp
The assignment is wrong: all of the following properties have special meaning in the DOM and are writeable:
alinkColor
bgColor
cookie
fgColor
linkColor
title
vlinkColor
The list above should work across different browsers. There are others (like charset and defaultCharset for IE, or some of these for Geckos) which don't, and not all of them are standard.
I think your assignment is based on out-of-date technology.
with Javascript, you can do anything after the webpage is rendered. e.g. changing the id name, properties, eventHandler, etc of any DOM dynamically.