javascript - Jquery element with dot in tag name -


jquery when tag string contains dot. when hard coded, query expected value, if tag obtained function , concatenated, query fails.

var tagwithdot = gettag(...) // tagwithdot === 'tag.withdot'  console.log(tagwithdot === 'tag.withdot') // true  console.log('#' + tagwithdot === '#tag.withdot') // true  console.log('#' + tagwithdot.replace('.', '\\.') === '#tag\\.withdot') // true  console.log($('#' + tagwithdot.replace('.', '\\.')) === $('#tag\\.withdot')) // false  console.log($(('#' + tagwithdot.replace('.', '\\.'))) === $('#tag\\.withdot')) // false 

instead of replacing manually . \\. stuff use jquery's escapeselector

var tagwithdot = "#tag.withdot";    console.log( $.escapeselector(tagwithdot) );
<script src="//code.jquery.com/jquery-3.1.0.js"></script>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -