Assign Element Name To Multiple Element's Names As A Prefix Using Jquery
I have a webpage that allows for dynamically generated content, I want to prefix all the dynamic content names with the name of the hidden element when they're created/before post
Solution 1:
Use this :
$("td input").each(function(){
$(this).attr("name",$("input:hidden").attr("name")+$(this).attr("name" ));
});
Explanation:
The first line iteratres through all the <input> elements inside <td> elements.
The second line concantates the name of the <input type = "hidden>" with the <input> element's name which is being iterated and assigns it to the name of currently iterated element.
The last line ends the function and each() method.
The
<input>elements must have a name before this script gets executed. The<script>tag must be placed just before the closing body tag or usewindow.onloadinstead, to confirm that the DOM has loaded.
Solution 2:
try this one .
$("td input").each(function(){
$(this).attr("name",$("input:hidden").attr("name")+$(this).attr("name"))
});
Post a Comment for "Assign Element Name To Multiple Element's Names As A Prefix Using Jquery"