javascript - can't select parent html tags from a html string, using jquery? -


I'm trying to select the tag from the link tag and wrapper-main class (and what's inside) JQuery With string but I can only select inner tags like ".text" and "#logo". Here is my javascript code:

The data string is that I can select ".text" and ".image".

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Head lang = "en" & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Link rel = "shortcut icon" href = "" & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div class = "main-cover" & gt; & Lt; Div class = "text" & gt; Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> Hi this is an example text & lt; Br> & Lt; / Div & gt; & Lt; Img id = "logo" class = "image" src = "" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

When you set up HTML If the problem occurs, jQuery has removed the HTML, head, and body tag. You need to use filters.

  newDom.filter ("main-cover"). Attr ("class");  

For your way of working, you have to wrap the data in a div.

var newDom = $ ("& lt; div & gt;"). Html (data); $ ("Main-cover", new dom) .attr ("class");

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -