Select element with percent sign (%) in its id with jQuery

html, javascript, jquery

Solution

You can use attribute selector, giving id in quotes will get the exact id.

Live Demo

$('[id="my%20id"]')

Problem

I have an element like this: ``` <a id="my%20id" href="#">hello</a> ``` I've been trying desperately to select it with jQuery, but cannot. I've tried: ``` $('a#my id') // obviously won't work $('a#my\ id') // no such luck $('a#my%20id') // unrecognized expression $('a#my\%20id') // still unrecognized $('a#' + encodeURIComponent('my id')) // same thing as 'a#my%20id' ``` Is it possible to select this at all with jQuery?

Original source

Related problems