what I want something like this
var newDiv = document.createElement("div");
newDiv.innerHTML = data;
var List=newDiv.$(".myclass h4");
console.log($(List[0]).html());
but it doesnot work.
If you make that newDiv a jQuery object, and then use find(), you can get the other element within it.
$(newDiv).find(".myclass h4");
Stack snippet
var data = "<div class='myclass'><h4>hello</h4></div>"
var newDiv = document.createElement("div");
newDiv.innerHTML = data;
var List = $(newDiv).find(".myclass h4");
console.log( $(List).html() );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
An alternative is passing as the second parameter the created element as the parent/source DOM element to find elements from it.
$(".myclass h4", newDiv); <--- This call returns a jQuery object.
^
|
+--- Parent/Source element
var newDiv = document.createElement("div");
newDiv.innerHTML = '<div class="myclass"><h4>Ele from Stack</h4></div>';
var list = $(".myclass h4", newDiv);
console.log(list.html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
$(List).html()instead of$(List[0]).html()? What “first element” are you trying to access? What precisely does “doesn’t work” mean?