Reputation: 105210
This is my code (jquery 2.0.3):
alert($('<p>test <b>me</b></p>').filter('p').get(0).html());
Chrome says:
Cannot call method 'html' of undefined
What's wrong?
Btw, I'm expecting test <b>me</b>
.
ps. My problem is that I'm running this from XSLT, not HTML. But thanks everybody for your answers.
Upvotes: 1
Views: 147
Reputation: 646
If you were to use .get(0)
then you would get back the actual DOM element, not the jQuery object. So you'd have to use standard DOM stuff.. in this case
$('<p>test <b>me</b></p>').filter('p').get(0).innerHTML;
Otherwise if you wanted to keep it all jQuery, you could say
// based on the .get(0) I'm assuming you want the first matched element?
$('<p>test <b>me</b></p>').filter('p').eq(0).html();
And to grab every paragraph's html
$('<p>test <b>me</b></p>').filter('p').html();
Upvotes: 1
Reputation: 10736
Remove the .get(0)
method.
alert($('<p>test <b>me</b></p>').filter('p').html());
Upvotes: 6