Different results for same jQuery code in chrome and Firefox
I can't figure out what the problem is. The following code works well in
Chrome (v29) but not on firefox (v23):
var serviceOptions = '<optgroup label="Domiciliary Care"><option
value="1">Meals</option><option value="2">Personal
Hygiene</option></optgroup><optgroup label="Live in Care"><option
value="3">Housekeeping and Cleaning</option><option value="4">Assisted
Mobility</option></optgroup>';
var cat = "Live in Care";
var escaped_cat = cat.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, "\\$1");
var options = $(serviceOptions).filter("optgroup[label='" + escaped_cat +
"']").html();
var expectedOptions = '<option value="3">Housekeeping and
Cleaning</option><option value="4">Assisted Mobility</option>';
// OK in Chrome, ERROR in FF
console.log(options == expectedOptions ? "OK" : "ERROR")
// passing the string directly instead of using a var works on FF
options = $(serviceOptions).filter("optgroup[label='Live\ in\
Care']").html();
console.log(options == expectedOptions ? "OK" : "ERROR")
The goal is simple as you can see: to filter a set of options by a
specific optgroup. You can test it by opening the jQuery website, opening
the console and copy-past the code. Meanwhile if I discover something,
I'll update this post.
No comments:
Post a Comment