anonamas
anonamas

Reputation: 241

Remove from select using jQuery

var currentSelect = 'option1';
$('#selectMail option[value=' + currentSelect + ']').remove();

What I am trying to do above is to remove a option from a select where the option value equals currentSelect. This however returns the error

Uncaught Error: Syntax error, unrecognized expression: #selectMail option[[email protected]]

What is happening here?

Upvotes: 0

Views: 54

Answers (2)

Scary Wombat
Scary Wombat

Reputation: 44814

try

$('#selectMail option[value="' + currentSelect + '"]').remove();

Upvotes: 1

codingrose
codingrose

Reputation: 15699

Value of attribute should be wrapped in quotes.

It should be

$('#selectMail option[value="' + currentSelect + '"]').remove();

Upvotes: 1

Related Questions