开发者

jQuery to get innerHTML not working on a HTMLFontElement object

开发者 https://www.devze.com 2022-12-24 13:32 出处:网络
I have jQuery to select all font elements that are children of the element with id=\"right\" within the html stored in the var html... when I do an alert to see how many elements it gets:

I have jQuery to select all font elements that are children of the element with id="right" within the html stored in the var html... when I do an alert to see how many elements it gets:

alert($("#r开发者_如何学Pythonight > font", html).length);

it gives me an alert of: 5

but when I try any of the following, I don't get any alerts...

alert($("#right > font", html)[0].html());
alert($("#right > font", html)[0].text());
alert($("#right > font", html)[0].val());

Any Ideas?

Thanks,

Matt


Since the element is not an instance of jQuery, and its just a DOM object you can't use any of the jQuery methods. You can use innerHTML to get the result.

alert($("#right > font", html)[0].innerHTML);

If you want to apply any of the jQuery methods to the element you have to make it a jquery object like

alert($($("#right > font", html)[0]).html());

or

$("#right > font").each(function(){
    alert($(this).html());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消