* 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?
2015-06-29 12:05 · (0)
* 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
2015-06-29 13:47 · (0)
* Aash * Graham Thanks... Nice to Learn!
2015-06-29 14:35 · (0)
* 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?
2015-06-29 16:40 · (0)
* 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
2015-06-29 22:30 (edited 2015-06-29 22:32 by Graham ) · (0)
* AH-SID * Graham oh yeah, it's work when I use another browser..

how about get teks for div tag without an attribute?
2015-06-30 02:46 · (0)
* 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
2015-06-30 08:21 · (1)

Online: Guests: 1