Reputation: 182
I am using jQuery DatePicker to select elements with '#', everything is working fine when i put "direct" string in the selector, but once i begin concatenating, the result is very suspicious. Maybe this console screenshot explain what i am struggling with
HTML :
<input id="wizard:wizard-body:datePiece_picker" name="wizard:wizard-body:datePiece_picker" type="text" value="">
Javascript :
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, "g"), replace);
}
var TYPEDIALOG = "wizard:wizard-body:";
var id = replaceAll(TYPEDIALOG, ":", "\\\\:")+ "datePiece_picker";
if ($("#" + id).length != 0) {
$("#" + id).datepicker({
dateFormat : "dd/mm/yy"
});
}
Upvotes: 0
Views: 58
Reputation: 27012
Your replace was adding too many backslashes:
var id = replaceAll(TYPEDIALOG, ":", "\\:") + "datePiece_picker";
As a side note, this is probably a pretty good argument for avoiding :
in element ids. Also, datePiece_picker
could be a class instead of part of the id.
Upvotes: 1