I'm trying to target a class within a script in console.log in Chrome; I get an error ClassName is not defined ?

if (getElementByClassName("class-name")){
document.write("correct class")
};
  • I wish email notifications would work on this site for me ;(

Where in the page is the script running? If it is before the element then your script is looking for an element that doesn't exist exist yet.
If you were using jQuery you'd wrap it in the document ready method. In plain javascript you'd call the function in the onLoad call in the body tag.
But seeing your code would help too.

The script is executed before the element; before I present the code, I must use onLoad to call the body tag ?

Something I forgot to mention, I want via the console.log to tell me whether or not a class or ID is loading an image which is nested within a anchor ?

Replace "getElementByClassName" to "getElementsByClassName"

I found that mistake that is not the issue :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.