简体   繁体   中英

jQuery parent element inner HTML

I am getting inner HTML of element by next way:

$(this).context.innerHTML

Then I am getting parent inner HTML:

$(this).parent().context.innerHTML

But this code returns same values. Any ideas what is wrong?

To get the contents of an element, then the contents of it's parent the jQuery markup would be

$(this).html();

and

$(this).parent().html();

http://api.jquery.com/html/

The context for both queries are the same, which in this case is the element that this represents. When you call parent() the context does not change. It is still the element that this represents.

You can specify the context of a query like this:

$("...", contextElement)

For more information visit:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM