Has anyone ran into an issue w/ the 'setAttribute' or jQuery's 'addClass' in IE?

All I'm trying to do is onclick change the class.

javascript attempt:

function expFolder()
  {
  var fold = document.getElementById("folder1");
  fold.setAttribute("class","folderExpand");
  document.getElementById("folder1").setAttribute("class","folderExpand");
  }

jQuery attempt:

$("#toggleClass").click(function()
  {

  $("#folder1").addClass("folderExpand");

  });

Tested fine in:
- chrome
- firefox
- opera
- safari

I appreciate any insight.

    i have tried ie 6-9. also, w/ my jquery i'm not using onclick - i'm referencing by id to run the click.

    i've also tried jquey's 'attr' w/ ("class", "newClass") and toggle... all fail in IE.

    not sure what step to take.

      Works in IE 7 and 9 for me. This is my complete code:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
          <title>Untitled Document</title>
          <style type="text/css">
              .folderExpand
              {
                  border:1px solid #000;
              }
          </style>
      
      <script type="text/javascript">
      $(document).ready(function()
      {
          $('#toggleClass').click(function()
          {
               $('#folder1').addClass('folderExpand');
          });
      });
      </script>
      </head>
      <body>
          <input type="button" value="Click me" id="toggleClass" />
          <div id="folder1" style="width:960px;margin:0 auto;background-color:#F00;height:500px;">
      
      </div>
      </body>
      </html>
      

        Thank You sir....

        $(document).ready(function(){});

        was the solution. I seem pretty good at forgetting to start my jQuery w/ that.

          You can also use the shorthand version:

          $(function() { });
            Derokorian;10997585 wrote:
            $(function() { });

            Nice! So, that line would completely replace the $(document).ready() ?

              Indeed. I'm not sure if its for all versions of jQuery or not but its at least 1.6 and above (that's the earliest version I ever used lol)

                Write a Reply...