- This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I was able to do this with jQuery but I’m wondering how I can do the following with strictly javascript.
Basically I want to add the attribute size=”2″ to the select element under the div with ID=”planSelectionDiv”.
I appreciate any help.
Anyone…Anyone…?
Something like?
var eSelect = document.getElementsById('planSelectionDiv ').getElementsByTagName('select');
eSelect.setAttribute("size", "2");
Not tested, just guessing!
You shouldn’t have to set a variable if you don’t want to. Depending on what you’re using it for, it probably is a better idea to. But just in case, here it is on one line.
document.getElementsById('planSelectionDiv ').getElementsByTagName('select').setAttribute("size", "2");
////////
Edit: Sorry, bad advice. After trying it out, apparently you can’t just chain them together like that. You have to use a variable like TT_Mark suggested.
@noahgelman As you have said, I *think* you can only chain like that in JQuery
Yeah, jQuery is pretty convenient for chaining things together.
A quick question though. if bzmillerboy simply wanted to set the attribute to 2 why go:
.attr("size", function() { return '2'; })
and simply not:
.attr("size", "2"})
No idea :S, although you have a typo in your second example
Oops, so I do. My bad. But still, that function he wrote confuses me