Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does not contain using jquery

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!

like image 854
Janet Avatar asked Jan 28 '26 07:01

Janet


2 Answers

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.

like image 34
T.J. Crowder Avatar answered Jan 30 '26 19:01

T.J. Crowder