Created
March 23, 2009 15:41
-
-
Save jonmagic/83603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm cloning a hidden row, but I need to remove the number from every id/name attr and replace it with a unique number, like 'new Date().getTime()' would work as the new number... | |
I found this jquery replace attribute function, but can't get it to work: | |
jQuery.fn.replaceAttr = function(aName, rxString, repString) { | |
return this.attr( | |
aName, | |
function() { return jQuery(this).attr(aName).replace(rxString, repString); } | |
); | |
}; | |
Here is the line I've got now thats using it: | |
$("#checklist table tbody tr:last").clone().removeClass("hide").insertBefore("#checklist table tbody tr:last").replaceAttr('id', /[0-9]/, new Date().getTime()); | |
Now I know thats not quite right cuz it is only replacing on the id's, and i need to do name's too... Below is an example of the html I'm trying to parse (these are all children of the #checklist table tbody tr)... | |
<input id="checklist_template_checklist_template_questions_attributes_0__delete" name="checklist_template[checklist_template_questions_attributes][0][_delete]" type="checkbox" value="1"> | |
<select id="checklist_template_checklist_template_questions_attributes_0_answer_type" name="checklist_template[checklist_template_questions_attributes][0][answer_type]"> | |
<textarea cols="40" id="checklist_template_checklist_template_questions_attributes_0_question" name="checklist_template[checklist_template_questions_attributes][0][question]" rows="20"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment