[英]jQuery to get innerHTML not working on a HTMLFontElement object
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: 我用jQuery选择所有font
元素,它们是var html
存储的html中id="right"
元素的子元素,当我发出警报以查看有多少个元素时:
alert($("#right > font", html).length);
it gives me an alert of: 5
它给我警报: 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. 由于元素不是jQuery的实例,而是DOM对象,因此您不能使用任何jQuery方法。 You can use innerHTML to get the result. 您可以使用innerHTML获得结果。
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 如果要对元素应用任何jQuery方法,则必须使其成为一个jquery对象,例如
alert($($("#right > font", html)[0]).html());
or 要么
$("#right > font").each(function(){
alert($(this).html());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.