Tag:html5csshtmljavascript
Article From:https://segmentfault.com/q/1010000012136048
Question:

Click on the picture, add a style (add a class name to him), and then click OK. Is it OK to get the SRC under this class name with JS? But why am I undefined?

Answer 0:

Because document.getElementsByClassName returns an array of objects, if your web page has only one picture of class user_photo_bord, you should write this:

document.getElementsByClassName("user_photo_bord")[0].src

Both getElementsByName and getElementsByTagName are returned to an element array, because in DOM, className, name, or label names may not be unique, onlyGetElementById will return to a specific element. If we observe carefully, we can find that the former is getElements and the latter is getElement, which is the difference.

Answer 1:

The way to get the element returns an array, first using the subscript.

Answer 2:

document.getElementsByClassName(‘use-photo_bord’)[0].src

Answer 3:

The third floor of the two floor is written right!

Leave a Reply

Your email address will not be published. Required fields are marked *