pstein Posted July 4, 2016 Share Posted July 4, 2016 Whenever I want to add something at the end inside an (the first) element which is identifiable by class name I can write:var div = document.getElementsByClassName("myclassname")[0];div.innerHTML = div.innerHTML + "foobar";This works fine.But what if there is no class name but only the element tag like in <cite> <span>01.07.2016</span> <span>sometext</span> </cite> How can I add "foobar" text at the end (after last span) but inside (!) the <cite> element?Is there a function similar to getElementByElementName(...) which means I could write:var div = document.getElementsByElementName("cite")[0];div.innerHTML = div.innerHTML + "foobar";Peter Link to comment Share on other sites More sharing options...
Ingolme Posted July 4, 2016 Share Posted July 4, 2016 It's called getElementsByTagName() and it's actually much older and better supported than getElementsByClassName. 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