jquery - How to change all control's name attribute inside a DIV -


i use below jquery change name attribute value iterate jquery. try assign id value name attribute of controls inside div , div id register. here code.

 $(document).ready(function () {             $.each($('#register').children(), function () {                 alert("pp");                 $(this).attr("name", $(this).attr("id"));             });         }); 

when running page above script suppose run not running. guide me made mistake. thanks

update

at last works

    $(document).ready(function () {         $('#register').find('*').each(function () {             $(this).attr("name", $(this).attr("id"));         });     }); 

try using .attr( attributename, function(index, attr) ) :-

$('#register').children().attr("name", function (index, oldname) {     return this.id || ''; }); 

fiddle demo


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -