SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object doesn't support this property in IE

    Hi everybody

    HTML Code:
    <a href="/">Home</a>
    <div id="links">
    <img name="ocean.jpg" src="horses.jpg">
    <a href="http://mysite.com" class="linkDynamic"> Download </a>
    <br>
    <img name="beach.jpg" src="2.jpg">
    <a href="http://mysite.com" class="linkDynamic"> Download </a>
    </div>
    <script type="text/javascript">
    
    var el = document.getElementById("links");
    
    var as = el.getElementsByTagName("img");
    
    var links = document.getElementsByClassName("linkDynamic");
    for (var i=0; i<as.length; i++) {
    
    
          var link = links[i];
          link.href = as[i].src;
    
          }
    </script>
    It works great in FF but IE says 'Object doesn't support this property or method'.
    I have page with static images, reading many posts I try put link for each image dynamically.
    I need help, I don't know how solve it.
    Tx

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    You will have to either use jQuery(which will make life very easy)

    or if you cannot you will need to remove the var links = doc.... section and loop thru all the <a> tags like you do with the <img> tags, checking what the class is

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you by reply
    I would like to use jQuery but I'm perfect newbie, I will try understand how do it.
    I will try second option, maybe easier to me.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    There are many getElementsByClassName functions that you can use.

    There is:
    Robert Nyman's Ultimate getElementsByClassName
    Douglas Crockford's getElementsByClassName
    Speed Comparison of getElementsByClassName which includes a tree walker, another ultimate version, Dustin Diaz's one and one specific to the prototype library.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Since browsers are just starting to implement that method directly the best solution is to test first if it exists and if it doesn't then add your own method to do it.
    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="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everybody
    Solved with
    The ultimate getElementsByClassName, anno 2008

    Great !

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    There is a good Quirksmode getElementsByClassName page that covers testing for the browser version first.

    The code goes:

    Code javascript:
    function getElementsByClassName(node, classname) {
    	if (node.getElementsByClassName)
    		return node.getElementsByClassName(classname);
    	else {
    		// your custom function
    	}
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you pmw57 !
    I learned with this post more than reading 2 months
    Nice Forum, thanks by all !


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
  •