niche Posted May 15, 2012 Share Posted May 15, 2012 (edited) How do you create an id for an element? I successfully created a paragraph with: var newLink = document.createElement('p'); //create paragraph and tried (unsuccessfully) to create an id with: newlink.setAttribute('id', 'noSug'); What's the right way? Edited May 17, 2012 by niche Link to comment Share on other sites More sharing options...
Don E Posted May 15, 2012 Share Posted May 15, 2012 When you created the paragraph, you have newLink as the var name. When you go to set the attribute, you have newlink(L is not cap). Try changing that and see if it works. 1 Link to comment Share on other sites More sharing options...
Ingolme Posted May 15, 2012 Share Posted May 15, 2012 Rather than setAttribute, set the id property of the element. 1 Link to comment Share on other sites More sharing options...
eTianbun Posted May 15, 2012 Share Posted May 15, 2012 Rather than setAttribute, set the id property of the element. newLink.id='noSug' 1 Link to comment Share on other sites More sharing options...
niche Posted May 17, 2012 Author Share Posted May 17, 2012 Lots of good advice. Thank-you for your help Don E, Ingolme, and eTianbun. Sorry it took so long to thank you. I was out for a couple days. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now