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?

1
  • 1
    side note if you're looking for <span> elements with a role="alert", using :contains(role...) won't work. You must do $('span[role="alert"]'). On a side note, always rap everything around with single quotes, using doubles only inside. Oct 1, 2012 at 17:17

2 Answers 2

13
$("span:contains('role=\"alert\"')")
4

You can simply use:

​$('span[role="alert"]')​​​​​​​​​​​​​​​​​​​.each(function() {        
    alert($(this).text());
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.