jquery - How escape spaces and "&" characters in the selector -


i escape spaces , & in id selector:

$("input[name='therapeuticarea']").click(function () {     var area = $(this).val(); // = "first & last"     $("div[id=" + area + ']').show(); }); 

i suggest using clean data-value="first-last" , using $(this).data('value')

so code like:

html

<input name="therapeuticarea" value="first & last" data-value="first-last"> 

js

$("input[name='therapeuticarea']").click(function () {     var area = $(this).data('value');     $("div[id=" + area + ']').show(); }); 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -