AH-SID
I have a problem. Like here..
Some HTML tags here...
<div id="wakwekwok">teks wak wek wok</div>
<div>another teks</div>
<div class="blekok">teks blekok nong nong</div>
Some HTML tags here...
What should I do to get teks "teks blekok nong nong" using JavaScript?
Graham
AH-SID <script>
var text=document.getElementsByClassName("blekok")[0].innerText;
document.write(text);
</script>
Copy code
The [0] tells it to use the first element in the document with that class name
[1] is the second element and so on
AH-SID
Graham it's undefined
but work when I use innerHTML.
can we get it by use another tags before, like using id=wakwekwok?
in css we can use plus sign (+): #wakwekwok + div + div
how about in js?
Graham
AH-SID Works fine in my test but innerHTML does just as well
var stuff=document.getElementById("wakwekwok").innerHTML
http://www.w3schools.com/jsref/met_document_getelementbyid.asp
AH-SID
Graham oh yeah, it's work when I use another browser..
how about get teks for div tag without an attribute?
Graham
AH-SID Without a id name or class you would use getElementsByTagName but you have to know how many div elements
http://www.w3schools.com/jsref/met_element_getelementsbytagname.asp