Posted By

tcam27 on 07/12/11


Tagged

html jquery names ids FormsElements


Versions (?)

Set All HTML Element Names and IDs to the Other


 / Published in: jQuery
 

Since forms only read the name of the element and not the id, this could be helpful since it makes each each element's name its id and its id the name.

  1. $(document).ready(function(){
  2. var thename;
  3. var theid;
  4. $('*').each(function() {
  5. if($(this).attr("name"))
  6. {
  7. thename=$(this).attr("name");
  8. $(this).attr("id",thename);
  9. }
  10.  
  11. });
  12. $('*').each(function() {
  13. if($(this).attr("id"))
  14. {
  15. theid=$(this).attr("id");
  16. $(this).attr("name",theid);
  17. }
  18.  
  19. });
  20. });

Report this snippet  

You need to login to post a comment.