Reputation: 1733
I have repetitive nobr tags which I can't add ID nor Class.
How do I find a specific nobr tag which contains a string of text?
<nobr>Due Date</nobr>
<nobr>Test</nobr>
<nobr>Hello</nobr>
$(document).ready(function() {
$('<nobr>Due Date').append('<span class="ms-formvalidation" title="This is a required field." > *</span>');
});
If I simply have:
$("nobr").append("*");
Then all nobr will be affected.
Upvotes: 0
Views: 629
Reputation: 213
http://api.jquery.com/contains-selector/
$(document).ready(function() {
$("nobr:contains('Due Date')").append('<span class="ms-formvalidation" title="This is a required field." > *</span>');
});
working example : http://jsfiddle.net/EnigmaMaster/FkZcY/
Upvotes: 2
Reputation: 87073
$('nobr').filter(function() {
return $(this).text() == 'Due Date';
});
Upvotes: 4
Reputation: 17666
$("nobr").each(function() {
if( $(this).text() == "hello world" ) {
// this is the element with the text in it
}
});
i'm no jQuery guy, there might be a better solution.
Upvotes: 1
Reputation: 10874
Use the containts pseudo selector like this
$("nobr:contains(Test)").append("*");
Here is the documentation: http://api.jquery.com/contains-selector/
Upvotes: 1