craigie2204
craigie2204

Reputation: 361

What am I doing wrong here with .not()?

var jobRole = $("select[name='location']").val();

$( "select[name='location']" )
    .change(function () {
       jobRole = $(this).val();
       $('#hiddenList li').appendTo('.content');
       $('.content li').not('+ jobRole').appendTo('#hiddenList');
       $('#PBANK_searchResult').pajinate();
       alert(jobRole);
});

If Edinburgh is select ".Edinburgh" appears as an alert ( I done this to check). However I was expeting that .Edinburgh would appear in the not() and resemble something like this:

$('.content li').not('.Edinburgh').appendTo('#hiddenList');

If I hardcord Edinburgh in to this the rest of the function works but I really need it to a variable depending on what is selected in the select box.

Thanks for your time

Upvotes: 1

Views: 72

Answers (3)

Jon Egerton
Jon Egerton

Reputation: 41539

You're using jobRole within the string selector - just a typo:

$('.content li').not('+ jobRole').appendTo('#hiddenList');

$('.content li').not(jobRole).appendTo('#hiddenList'); 
//Since you say the jobRole includes the '.' for the class selector

Upvotes: 1

Satpal
Satpal

Reputation: 133403

the variable already has the .

You need to use

$('.content li').not(jobRole).appendTo('#hiddenList');

Here jobRole is a variable so you don't need that in quotes

Upvotes: 1

Anton
Anton

Reputation: 32581

You need to do like this to use a variable

  $('.content li').not('.'+ jobRole).appendTo('#hiddenList');
  //                   ^^^^^^

Update newInfo

  $('.content li').not(jobRole).appendTo('#hiddenList');
  //                   ^^^^^^ no quotes

Upvotes: 2

Related Questions