0

How to replace form tag id with new id?

  <form method="post" action="contactus.aspx" id="ctl01">

replace id="ctl01" with id="validForm"

Update

look like ctl01 id generating by code. by the time we changing id name, 'crl01` is not available yet. How to handle after page loaded?

James123
  • 11,184
  • 66
  • 189
  • 343
  • Change the attribute value with .attr. http://learn.jquery.com | http://try.jquery.com – Kevin B Apr 02 '13 at 21:16
  • 2
    Open up your favorite HTML editor, delete `ct101` using the backspace key, type in `validForm` instead, save! Everybody happy happy? – adeneo Apr 02 '13 at 21:21

1 Answers1

4

Get the element in Javascript and change it.

document.getElementById('ctl01').id = 'validForm';

You can also use jQuery.attr();.

$('#ctl01').attr('id','validForm');

To wait for the DOM to load, use this:

$(document).ready({
  //DOM is ready
});

A common syntax is also this:

$(function() {
  //DOM is ready
});

There are also other ways, but these are the most common.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
  • look like ctl01 id generating by code. by the time we changing id it is not available yet. How to handle after page loaded? – James123 Apr 02 '13 at 21:23