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

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -