bonaca bonaca - 5 months ago 7
Javascript Question

How to get content of a child div?

Why this doesn't work:

<div class="store" id="vframestore">
<div>http://www.youtube.com/embed/_6DPBCOukLU?showinfo=0&modestbranding=1&fs=0&rel=0</div>
<div>http://www.youtube.com/embed/ZMr0q4Jz_uM?showinfo=0&modestbranding=1&fs=0&rel=0</div>
</div>


JS

var a = $("#vframestore").children[0].html;
console.log(a);



error: Uncaught TypeError: Cannot read property 'html' of undefined

Answer

You can do it like following.

var a = $("#vframestore").children().first().html();

Or

var a = $("#vframestore div").eq(0).html();
Comments