If I have HTML content in a variable like so:
var data = "<div id='myid'><div id='subid'>Text</div></div>";
Is there a way to query this using jQuery and selectors?
As this, if it were HTML DOM:
var data = $("#myid > #subid").text();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use jQuery’s context:
Your example is wrong in that it is trying to access the elements by class (“.subid”) instead of by id (“#subid”) – also, if you have an element’s ID, it is not necessary to do something like “#myid > #subid” as since there is only one ID per document (if you’re doing things properly, at least) then jQuery can just do the native document.getElementById() to find the element. I tested the above and it works fine.