Jump to content

getElementsByClassName() for element with multiple classnames?


pstein
 Share

Recommended Posts

Assume I want to get the content/Value of the following (inner) element (and move it later into another element):

< aside id="parent">
< p class=" aaa bbb ccc"> ...... </p>
< /aside>

then the following code does not work:

var pane = document.getElementsByClass("aaa bbb ccc")[0];
var target = document.getElementsByClass("foobar")[0];
target = pane.innerHTML;

The following does not work as well:

var pane = document.getElementsByClass("aaa.bbb.ccc")[0];
var target = document.getElementsByClass("foobar")[0];
target = pane.innerHTML;

So how else should I code this?

Peter

Link to comment
Share on other sites

1) There is no function of getElementsByClass() it should be getElementsByClassName();

2) You are asking it to assign innerHTML content of pane to target variable? not its innerHTML, so it will just overwrite var target = document.getElementsByClass("foobar")[0];

 

http://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp

Edited by dsonesuk
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...