Below is the function that I am using in jquery
function addlnkfieldmkAndyr()
{
var mymke = $('h3:contains("Make")');
var mymkeVal= $('h3:contains("Make")').closest("td").next();
var myyr= $('h3:contains("Year")');
var myyrVal= $('h3:contains("Year")').closest("td").next();
}
The problem that is there is another field with the name as MakeandYear , so mymkeVal and myyrVal are getting the values from MakeandYear instead of just Make.
I would like to say
string.Contains("Make") && !string.Contains("MakeandYear).
How do I do that in jquery , please help!
Use .not , like $("div").not(":contains('Test')") ...
See: http://jqapi.com/#p=not
Andrey pointed to the .not function, which is a perfectly good answer. You can also use the :not selector, in combination with :contains (live example):
var mymke = $('h3:contains("Make"):not(:contains("MakeAndYear"))');
The advantage of :not (the selector) over .not (the function) is that you don't add unnecessary elements to the jQuery object and then remove them. Does it matter? Almost certainly not, and be careful making any performance assumptions, although I think your use of :contains means throwing :not in won't do any harm. You'd have to have a truly enormous number of h3s for it to matter either way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With