steamboy
steamboy

Reputation: 1162

jQuery selectors with meta-characters

I'm having problem selecting an element with an id like this <li ="0f:Bactidol_Recorder.mp4">.

I tried using the function that escapes meta-characters with two backslashes below from this jquery link but still can't select the element

Function:

function jq(myid) { 
   return '#' + myid.replace(/(:|\.)/g,'\\$1');
}

Example:

$(jq('0fb:Bactidol_Recorder.mp4')).empty()

Output:

$(#0fb\\:Bactidol_Recorder\\.mp4).empty();

Upvotes: 1

Views: 2008

Answers (1)

SLaks
SLaks

Reputation: 887415

EDIT: Your original code works fine. (jQuery 1.4.2)

You could write

$('*[id="0fb:Bactidol_Recorder.mp4"]')

However, it'll be slower.

The fastest way to do this would be to write

$(document.getElementById("0fb:Bactidol_Recorder.mp4"))

Upvotes: 2

Related Questions