Get text from selector in jquery – wordpress

I want to take the text of first row from body in wordpress and I have some problems.

My code:
HTML CODE

<body id='asd'>
   <h2>Text1</h2>
   <p>Text2</p>
   <b>Text3</b>
</body>

JS CODE:

console.log(jQuery('#asd').children(':first').text());

This code is working locally. It will output in console, exactly what I need:
Text1, but, in wordpress doesn’t work.

If I try the same code on wordpress, no output is show.

If i try:

console.log(jQuery('#asd').children(':first'));

On local output is: [h2, prevObject: r.fn.init(1)]
On wordpress output is: [selector: "", prevObject: a.fn.init, context: document]

Can someone help?

Read more here: Get text from selector in jquery – wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *