SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object doesn't support this property or method

    hi,

    I get an error when I try to dynamically add an attribute to some elements, since I been getting the error "Object doesn't support this property or method" in IE I reduced the attribute value to just alert.

    Code JavaScript:
    function initialize_containers()
    {
    	var containers = document.getElementsByClassName("boxcontainer");
     
    	var i = 0;
    	for (i = 0; i < containers.length; i++)
    	{
    		containers[i].setAttribute("onmouseover", "alert('hello world');");
    	}
    }
     
    window.onload = function() { initialize_containers(); };

    note that in firefox all the elements with the class boxcontainer gets "hello world" alert. I removed this specific code (shown above) out of the page and the error in IE goes away, so I'm 100% sure nothing else is causing it. Any suggestions?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    AFAIK, IE's document object doesn't support getElementsByClassName()

    Can you get them some other way? eg. Id or tag?

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    AFAIK, IE's document object doesn't support getElementsByClassName()

    Can you get them some other way? eg. Id or tag?
    It uses span tag, but other than that assigning id's to all the spam is not an option, is there a IE alternative workaround for getElementsByClassName?

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)

  5. #5
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Doesn't IE also have issue with the setAttribute (esp with something like an attribute of "alert()")??

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Doesn't IE also have issue with the setAttribute (esp with something like an attribute of "alert()")??
    That's exactly the problem I'm facing now! I was just about to start a new thread, but was not sure whether I should or not.

    Now that I can get elements with boxcontainer, I am now facing the problem with setAttribute("onmouseover", "alert('hello world');");

    since there will be parameters can't use it like element.onmouseover = iframeshim; where iframeshim function would have parameters.

    Could anyone suggest alternative method to setAttribute?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by cssExp View Post
    That's exactly the problem I'm facing now! I was just about to start a new thread, but was not sure whether I should or not.

    Now that I can get elements with boxcontainer, I am now facing the problem with setAttribute("onmouseover", "alert('hello world');");

    since there will be parameters can't use it like element.onmouseover = iframeshim; where iframeshim function would have parameters.

    Could anyone suggest alternative method to setAttribute?


    Code:
    element.onmouseover = function() {iframeshim(parm1,parm2)};
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah I didn't know it can be used like that, always thought anything used within function() { ... } got executed immediately.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by cssExp View Post
    Ah I didn't know it can be used like that, always thought anything used within function() { ... } got executed immediately.
    No it only gets executed immediately if you add () to the end like this:

    element.onmouseover = function() {iframeshim(parm1,parm2)}();
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •