Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple JQuery selector does not find ID within a string

Tags:

jquery

string

var chk = "<div id='test'>Trying</div>";

    alert($("#test",chk).html());

Well this JQuery by String is not working its so simple but it doesn't work =/ What is it wrong in it ? thanks in advance!

like image 321
Grego Avatar asked Mar 11 '26 05:03

Grego


1 Answers

Try something like this:

var chk = "<div><span id='test'>Trying</span></div>";
alert($("#test",chk).html());

The first parameter "#test" is your selector (what you really want to get).

And the second parameter chk is your context (within your query / search is performed).

like image 190
SunnyRed Avatar answered Mar 12 '26 19:03

SunnyRed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!