4

I have read several posts regarding usinq quotes in jQuery and have not been able to form my own query. I have to check a span tag for a particular string. The string i am searching for is: role="alert" (it has double quotes around the word alert.

$("span:contains('role="alert"')").each(function() {        
        alert($(this).text());
    });

Can someone provide a query for this?

4

2 回答 2

13
$("span:contains('role=\"alert\"')")
于 2012-10-01T17:03:37.053 回答
4

您可以简单地使用:

​$('span[role="alert"]')​​​​​​​​​​​​​​​​​​​.each(function() {        
    alert($(this).text());
});
于 2012-10-01T17:06:29.467 回答