I am trying to get the text:
$("#id td div")[1].text();
But it return:
TypeError: undefined is not a function
When I try without text:
$("#id td div")[1];
It return the div... without error...
<div>$ 1000.00</div>
How can I get the text ? $ 1000.00
Thanks!
Just try with:
$($("#id td div")[1]).text();
[1]
returns you plain DOM object. You have to wrap it with jQuery again to use .text()
jQuery function.
Otherwise you can use:
$("#id td div")[1].innerHTML;
or:
$("#id td div:eq(1)").text();
这应该为您提供文字。
$("#tdCartoesCheques td div").text()
A jQuery object is an array of DOM elements, which means when you access the array by index, you get a DOM element and not a jQuery object. For this purpose, jQuery has the :eq()
selector:
$("#tdCartoesCheques td div:eq(1)").text();
http://api.jquery.com/eq-selector/
As an alternative, this would also work, but is a bit more verbose and probably slower:
$($("#tdCartoesCheques td div")[1]).text();
$("#tdCartoesCheques td div:eq(*the index*)").text();
索引从0开始。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.