Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i set id from js ?

Status
Not open for further replies.

heeeep72

Programmer
Dec 15, 2004
33
CH
Hi!

can i set the id of an HTML element from javascript same way as f.e. the bordercolor??

Code:
function myFunct(myElement) {
...
		myElement.style.borderColor = '#DF5456';  // this works
		myElement.id = "blabla";                  // this ?
...
}

thanks in advance!!!
h
 
Hey Adam0101 !

WOW this was fast! :)

The question is: how ?
(because in the above mentioned way it did not work for me.... or have I made some stupid typo again ?)

thx
 
heeeep72, although what you're trying should work, you may want to look into the javascript method [!]setAttribute[/!]. You may have more luck with that. You can copy/paste the example below into a new page to see how it works.
Code:
<script type="text/javascript">

function blah(obj) {
   obj.[!]setAttribute("value", "I've been clicked")[/!];
   obj.[!]setAttribute("id", "thatWasntSoHard")[/!];
   alert(obj.id);
}

</script>

<input type="button" value="click me" id="theHardestButtonToButton" onclick="blah(this)" />

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top