Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Hey guys, i'm having this problem. I understand that IE does not do addEventListener. So i tried doing the attachEvent. Yet attachEvent doesn't give you the option to target (this = window ?!?) the object that is attached to the eventListener. Soooo... i'm kind of confused as to how to tell IE to understand:

    1. take element that is clicked on
    2. chagne its title and its brothers class name


    Code:
    var boardMembs = ["mPBrasted", "one", "two", "three"];
    	
     function setupItems()
     {
    	for (var i=0; i< boardMembs.length; i++)
    	{
    	 	var currentID = document.getElementById(boardMembs[i]);
    		
    		if (currentID.addEventListener)
    		{
    			currentID.addEventListener('click', expansionFx, false);
    		}
    		else
    		{
    			//something for IE
    			//currentID.attachEvent('onclick', expansionIE);
    		}
    	}
     }
     
     function expansionFx()
     {
     	var curTitle = this.getAttribute("title");
    
    	var getHiddenElement = this.nextSibling.nextSibling;
    
    	if (curTitle == "inactive")
    	{
    		this.setAttribute("title", "active");
    		getHiddenElement.setAttribute("class", "boardMembBody active")
    	}
    	else
    	{
    		this.setAttribute("title", "inactive");
    		getHiddenElement.setAttribute("class", "boardMembBody inactive");
    	}
    	
     }
     
     function expansionIE()
     {
    	//soemthing for IE
     }

  2.  

  3. #2
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    I actually wrote a wrapper for addEventListener and attachEvent once, which basically abstracts the whole thing and allows you to use it as you'd use addEventListener, with one difference: instead of obj.addEventListener(blah blah), you use addListener(obj, blah blah). The code is on http://nerdforum.tripod.com/browserextensions.js (see addListener and removeListener).
    Hyperair

  4. #3
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    hyperair's solution is definitely one way to go; another is to just use one of the cross-browser libraries like jQuery and have done with it; they abstract just about all of this away for you so you don't have to worry about it.

  5. #4
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    ok cool. Thanks guys! I'm starting to think more and more about jquery. Is there a point in using javascript if something like jquery exists?

  6. #5
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    ok wait... i was ABOUT to go jquery and see if I can figure it out, when I decided to see what Microsoft had to say about this ordeal.... and that's when it happened. I found this:

    http://social.msdn.microsoft.com/For...-c629194e1b87/

    ... where the guy describes this:

    Code:
    function myEventHandler( e ){
      if(!e){var e = window.event;}
      if(!e.target){e.target = e.srcElement;}
      //do your stuff...
      alert('You just ' + e.type + 'ed on the ' + e.target.nodeName + ' element with the name ' + e.target.name);
    }
    ... so I took his idea and started playing with e and its equivelents.... and then... :laugh:


    IT WORKED! IE 7 and even IE6! WOOWOO! Thusfar doesn't work in IE8 Standards Mode

    Here is the code and its SUPER easy:

    http://friendpaste.com/5aZA2XGwUieOrEBJuppYZD

    I think what I gather from this is that IE does't do "this" on event listeners, but it does do "e"

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    To answer your previous question, jQuery IS Javascript. It's just a prettified API for certain parts of the DOM and such. It's dangerous to forget that jQuery is Javascript, as it has all the limitations and all the caveats and, fortunately, all the considerable boons of JS.

    As to whether it's worth it to use straight-up JS, load time is a slight concern, and jQuery is something that has to be downloaded before everything on your page can work. That said, with proper caching, gzip compression, and getting the minified version of jQuery, the overhead on modern connections is minimal and the benefits are considerable. I have used a JS library of some sort (prototype, jQuery, etc) for the last three or four years on just about every project, and never regretted it.

    EDIT: Also, IE's lack of support for this using addEventHandler and such almost certainly does not extend to explicitly setting the event handler on the object (e.g., [minicode]document.getElementById('myElement').onClick = function() { ... }[/minicode]). These are, however, somewhat less flexible than the addEventHandler method, and I'm not sure that they catch bubbled events.

  8. #7
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Quote Originally Posted by Shadowfiend
    To answer your previous question, jQuery IS Javascript. It's just a prettified API for certain parts of the DOM and such. It's dangerous to forget that jQuery is Javascript, as it has all the limitations and all the caveats and, fortunately, all the considerable boons of JS.

    As to whether it's worth it to use straight-up JS, load time is a slight concern, and jQuery is something that has to be downloaded before everything on your page can work. That said, with proper caching, gzip compression, and getting the minified version of jQuery, the overhead on modern connections is minimal and the benefits are considerable. I have used a JS library of some sort (prototype, jQuery, etc) for the last three or four years on just about every project, and never regretted it.

    EDIT: Also, IE's lack of support for this using addEventHandler and such almost certainly does not extend to explicitly setting the event handler on the object (e.g., [minicode]document.getElementById('myElement').onClick = function() { ... }[/minicode]). These are, however, somewhat less flexible than the addEventHandler method, and I'm not sure that they catch bubbled events.
    Right, I do understand that JQuery is Javascript. I'm under the mentality to learn the underlying language first before jumping into a framework, like AS & Flex. I didn't want to use the event handler on the individual object, because that is less flexible. I also wanted to build the way it is for my own experience.

    Anyhow, its nice to know that a form of the eventHandler works in IE. Now I just have to figure it out for IE8, yet I have some time for that.

    Thanks for the help guys!

  9. #8
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    And that is most definitely a good way to go. What's IE8 doing/messing up on?

  10. #9
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Quote Originally Posted by Shadowfiend
    And that is most definitely a good way to go. What's IE8 doing/messing up on?
    i dunno, weird. Here is the link: http://www.nasvf.info/boarddirectors.php

    perhaps it doesn't understand "nextSibling" as i'm getting this error:

    Code:
    'srcElement.nextSibling' is null or not an object

    I'm using the IE8 meta tag fix to make IE8 behave. However, it is disabling the menu bar. Odd.

  11. #10
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    oh wait, i fixed it! LOL

    basically, IE6 & 7 didn't want to read an attribute "class". They had to have "className". But IE8 didn't want to do "className", it only wanted "class". SO i already had conditionals for browser makers, now I have conditionals for browser models. LOL... The part added starts at line 54. Here is the code: http://friendpaste.com/3LfBHJ66mkbCKaDwyf0V19


Posting Permissions

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

Search tags for this page

addeventlistener ie11
,
addeventlistener is null or not an object
,

attachevent ie11

,
ie 11 addeventlistener
,

ie 11 attachevent

,

ie11 addeventlistener

,
ie11 attach event jquery
,

ie11 attachevent

,
ie11 attachevent vs addeventlistener
,
jquery ie11 attachevent
Click on a term to search for related topics.
All times are GMT -6. The time now is 01:07 AM.
Powered by vBulletin® Version 4.2.0
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com