Solved

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

Posted on 2014-10-01
3
106 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

785 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