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
Post a Comment