Get value of node with a certain ID
If I have something like:
<h1 id="someID">
<span id="genericID">someValue</span>
</h1>
How can I get the value of genericID span element, that is, someValue using the id ,someID, of the h1 element? I can get document.getElementById('oc-title-id').innerHTMLand then do a rege开发者_如何学运维x, but is there any other way? Using JQuery or Javascript?
You can use $('#someID').text()
Or for javascript only document.getElementById('someID').innerHTML
Use:
$('#someID').text();
Since a span doesn't have a value (though input elements do).
You could, potentially, use:
$('#someID').html();
But that, as the method-name implies, also retrieves the html of any nested elements.
Either $('#someID').html() or $('#someID').text(), depending on exactly what you want to extract.
加载中,请稍侯......
精彩评论