假设以下html
<div>Random content can go <font size="50">here</font> with forn elements
<font size="50">mixed into the text</font>, in random positions.</div>
检索文本如下
//first get all elements with the appropriate selector
var $fontElements = $("font[size='50']");
//then access them one by one using .each(). $(this).text() gets the actual text
$fontElements.each(function (index) {
var line = "element " + index + "=>" + $(this).text();
$("#result1").append(line);
$("#result1").append($("<br>"));
});
//using .text() right away will mix all the elements into one continous sting.
$("#result2").text($fontElements.text());
上面的输出将给出
结果1
element 0=>here
element 1=>mixed into the text
结果2
heremixed into the text
这是 jsfiddle 的链接和一个工作示例http://jsfiddle.net/Df9h9/