Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript code not working 3 32
javascript form - error when hitting enter 3 28
Why is my $_POST not going to results page 10 36
web page freezes after ajax post 7 46
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

749 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