Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Element setAttribute() method.

  • 24-02-2010 06:44PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 1,919 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 1,919 ✭✭✭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, Registered Users 2 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