Solved

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

Posted on 2014-10-01
3
102 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
Comment Utility
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
Comment Utility
@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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now