Solved

I am Getting an Error Unable to set value of the property 'className': Error?

Posted on 2014-10-01
3
105 Views
Last Modified: 2014-10-02
I am setting a class to a different class.

I am doing the coding as follows:
document.getElementById("prevowners-section").className = "subnav-target";

When the new class name is entered, an error occurs:
Unable to set value of the property 'className':  object is null or undefined

Thanks,

Dan
0
Comment
Question by:danielolorenz
  • 2
3 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 40354541
Test page : http://jsfiddle.net/rqLmgjjp/

document.getElementById("prevowners-section").setAttribute("class", "subnav-target");

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 40357009
@Leakim: Identical result

http://jsfiddle.net/mplungjan/83v9mqef/
document.getElementById("prevowners-section1").setAttribute("class", "subnav-target");
document.getElementById("prevowners-section2").className="subnav-target";

Open in new window


More likely need is to use
window.onload=function() {
  document.getElementById("prevowners-section").className="subnav-target";
}

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 40357106
Hi, not to be picky, but what was Leakim's contribution to solving your issue?

If the issue was that the prevowners-section was not rendered at the time you executed your script, then the window.onload was the solution.

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now