I am new at JavaScript so I think my problem may be simple.
This works:
var convId = document.getElementById("wrapper");
convId.setAttribute("align","right");
But when I try to make it more specific:
var convId = document.getElementById("wrapper");
var convIdDl = convId.getElementsByTagName("dl");
convIdDl.setAttribute("align","right");
my definition list doesn’t align to the right.
I have checked the HTML and CSS and everything is correct, but that shouldn’t even matter
JavaScript overwrites them both.
The
getElementsByTagNamemethod returns a collection (to be more specific, aNodeList). You need to specify which element of that collection you want to use (just like you would when accessing an element in an array). Here I’m assuming you want the first:As noted in the comments, you should definitely not be using the
alignattribute. CSS should be used in all cases.