I have a bunch of HTML list items and what I want is that they can read the list of the list item and then the user Be able to give it the ability to modify it. The structure of each list object is the same:
& lt; Li id = '1' class = 'attachment' & gt; & Lt; A href = 'link.html' & gt; Read VALUE I want to read and improve & lt; / A & gt; & Lt; A href = 'link2.html' & gt; & Lt; Img src'img1.jpg '& gt; & Lt; / A & gt; & Lt; A href = 'link3.html' & gt; & Lt; Img src'img2.jpg '& gt; & Lt; / A & gt; & Lt; / Li & gt;
At this time I am able to get inventory using
li = document.getElementById (id);
But if I think
li.childNodes [?] Li.childNodes [?]. Data li.childNodes? ] .nodeValue etc ...
I have never enabled it to print "read and improve text", it always gives blank, undefined or [object text] or Something similar Any help will be very much appreciated.
You need to get textContent or internal text < / Em> Properties:
var li = document.getElementById (id); Var t = "textContent" in li.childNodes [0]? "Text Content": "Inner Text"; Warning (li.childNodes [0] [T]);
Internal text has been implemented by IE and implemented by browsers according to the textContent standards.
Alternatively, if you are certain that the first child of the element will be a text node, you
warnings (li.childNodes [0] .childNodes [0] .nodeValue);
Depending on your comment below, we can make a safe assumption that white space is interfering with childNodes property in your example. Normal - Both the elements and text nodes are given child nodes , which are the straight line of the given element. In alternative new browsers, use children :
// Instead of using Leeds, first Li = document.getElementById (id); Var t = "textContent" in Lee? "Text Content": "Inner Text"; Warning (li.children [0] [t]); // second example 'using alerts instead of children (li.children [0] .childNodes [0] .nodeValue);
Kids are not supported in previous Firefox 3.5 and other older browsers, for example you li.getElementsByTagName ("a") - but keep in mind that it's all & lt; A & gt; Element will return the descendants, not just the immediate child.
Comments
Post a Comment