I'm using a :regex library (found here) to select elements that have IDs starting with P and having at least 5 digits afterward. Then, I use .attr to add on some attributes.
$(document).ready(function() {
$('img:regex(id,P[0-9][0-9][0-9][0-9]+)').attr("onmouseover", "show\(this\,2\,0\)");
$('img:regex(id,P[0-9][0-9][0-9][0-9]+)').attr("onmouseout", "hide\(this\)");
});
This works in Firefox, but not Chrome. (Haven't tested IE yet.)
I tried using [0].setAttribute instead, and it works to an extent, but then for some reason it only selects the first instance of the regex.
Does anyone have a more compatible solution?
Whatever that plugin does, it looks terribly slow. I would rather recommend to select all image nodes and then filter them with jQuery
.filter()
help, this has to be faster and I think it's still more readable at all. Could look like:Demo: http://www.jsfiddle.net/snMCM/
Performance benchmark: http://jsperf.com/regex-vs-jquery-filter