user1060500
user1060500

Reputation: 1535

Use JQuery selector on a string of HTML content

I have a string of HTML content I am getting back as a Partial View from ASP.MVC. I don't want to render this anywhere on the page, rather I want to use JQuery to select certain elements out of the HTML returned content and do things with it.

Is it possible to use JQuery selectors in this way without the HTML being rendered on the page?

Upvotes: 0

Views: 36

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Yes, you can.

var html = '';
var $html = $(html);
//then do normal stuff with $html like
$html.find('input[name="x"]').val();//will get the value of the input with name x
$html.find('.tester').text();//will get the text content of element with class tester

Upvotes: 2

Related Questions