Search code examples
javascriptjquerystring-concatenation

jquery variable substitution


this works ..

$("select[title='First Choice'] option[text='hello']").remove();

A number of variations of this does not .. i know this is stupid.

var what='hello';

    $("select[title='First Choice'] option[text=$what]").remove();

also tried these.

$("select[title='First Choice'] option[text=$(what)]").remove();
$("select[title='First Choice'] option[text='$what']").remove();
$("select[title='First Choice'] option[text=$what.val()]").remove();

Solution

  • You want this:

    $("select[title='First Choice'] option[text=" + what + "]").remove();