Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Element setAttribute() method.

Options
  • 24-02-2010 6:44pm
    #1
    Registered Users Posts: 3,078 ✭✭✭


    Is the form below a valid method of changing the id of an XHTML
    element, specifically the one actually being referenced? It does not
    seem to work for me.

    document.getElementById("Original_Name").setAttribute("id", "New_name");

    I have also tried:

    var curentHiddenElement = document.getElementById('Original_Namet');
    curentHiddenElement.setAttribute('id', 'New_name');


Comments

  • Registered Users Posts: 1,916 ✭✭✭ronivek


    EDIT: On second glance; I got the question completely arseways I think. Shows how much web development I do.

    Hopefully nobody was quick enough to notice...

    Anyhoo; what are you actually trying to do once you've altered the element?


  • Registered Users Posts: 3,078 ✭✭✭onemorechance


    XHTML and XML are essentially the same when it comes to the DOM. I think the method works, but the browser does not allow the id of an element to change once it is loaded as it could cause problems with the DOM.


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    mairtin888 wrote: »
    XHTML and XML are essentially the same when it comes to the DOM. I think the method works, but the browser does not allow the id of an element to change once it is loaded as it could cause problems with the DOM.

    XHTML is effectively XML for all intents and purposes; so that's not the issue.

    I merely assumed the function was returning all elements by element name and not searching through id attributes.

    I would imagine it is as you say; but I'll bow (not so) gracefully out as I've little web development experience.


  • Registered Users Posts: 3,078 ✭✭✭onemorechance


    Thanks for your help anyway. I'll get ya back sometime! It is possible to change the id, but it is considered bad practice, and I guess browsers don't allow it once the DOM is loaded.


Advertisement