2
var html = '<div class="item">abcabc<span>sasd</span></div>';

How can I use JQuery to retrieve the stuff inside "item"? I want to get the HTML inside of this item...as a string.

2 Answers 2

3

Since the root of your HTML string is that .item, it's simply a matter of passing the whole string into the $() function and invoking .html() on the jQuery-wrapped element:

var string = $(html).html(); // 'abcabc<span>sasd</span>'
Sign up to request clarification or add additional context in comments.

Comments

0

Just

var html = $('<div class="item">abcabc<span>sasd</span></div>');
var content = $(".item", html).html();

1 Comment

.item is the root element in the string, so $(".item", html) actually finds .item .item, which is incorrect.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.