How can I find a td class in a string? (jQuery)
string="<td class=\"en\">enenene</td><td class=\"ro\"&开发者_如何学Gogt;rorororo</td>";
Example:
string.$('td.ro').html();
$(string).filter('td.ro').html();
You can do this way. Pretty dirty though!
var string = "<td class='en'>enenene</td><td class='ro'>rorororo</td>";
var h = $(string);
h.each(function(){
if($(this).attr("class") == "ro"){
//We've found the td
}
});
See the dome on jsfiddle: http://jsfiddle.net/naveed_ahmad/bMfqj/
Using a find
by itself doesn't work. But if you have well-formed HTML, you can use jQuery's parseXML
function:
var str = "<div><td class=\"en\">enenene</td><td class=\"ro\">rorororo</td></div>";
var xml = jQuery.parseXML(str);
var $xmlDoc = jQuery(xml);
console.log($xmlDoc.find("td.ro"));
Note: This only works in jQuery 1.5 and later.
EDIT: Actually you can use filter
(look at brad's solution). That's probably what you want.
精彩评论