Set All HTML Element Names and IDs to the Other


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.