<div id="id1" class="desc">Hello World 1</div>
<div id="id2" class="desc">Hello World 2</div>
<div>test</div>
In document.ready,
$(function(){
var $dvObj = $('div.desc');
alert($dvObj[0]);
alert($dvObj[0].text()); //Nothing comes up
alert($dvObj[0].html()); //Nothing comes up
});
I am not able to get the div html. Pls suggest.
When you use square brackets to access an element of a jQuery object you get the actual DOM element, not a jQuery object. DOM nodes don’t have a
textorhtmlmethod.You can use the
eqmethod to get a jQuery object containing the element at the specified index: