Solved

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

Posted on 2014-10-01
3
111 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

696 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