ie getAttribute problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    ie getAttribute problems

    Hi, so i done script like that

    Code:
    	body : function() {
    		for (i = 0; i < all_divs.length; i++) {
    			if (all_divs[i].title) {
    				addEvent(all_divs[i], "mouseover", this.onover);
    				addEvent(all_divs[i], "mouseout", this.onout);
    
    				all_divs[i].setAttribute("tooltip", all_divs[i].title);
    				all_divs[i].removeAttribute("title");
    			}
    		}
    	}, 
    	
    	onover : function() {
    		var msger = document.getElementById("msger");
    		msger.innerHTML = this.getAttribute("tooltip");
    	},
    So firefox prints out tooltip but the ie6 doesn't so what should i do that ie would print tooltip attribute
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hmmm, strange ... is it a problem with getAttribute() or another one? when you assign a fixed text is that displayed in the innerHTML of 'msger'?

    kind regards

    Comment

    • tader
      New Member
      • Sep 2007
      • 43

      #3
      the problem is with getAttribute(); ie can not get it if i do it like that all_divs[0].getAttribute(" tooltip"); it works but when im using this.getAttribu te("tooltip"); it doesn't work on ie on ff everything is ok. I need it to work on this.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        could you trace that this.tagName is the div you want to retrieve? may be you could try an additional property for the div like:

        [CODE=javascript]all_divs[i].tooltiptext = 'your_text';
        [/CODE]
        and later on retrive it with:

        [CODE=javascript]this.tooltiptex t;[/CODE]
        kind regards

        Comment

        • tader
          New Member
          • Sep 2007
          • 43

          #5
          hm... that didn't work dam it ;] mabey if i give you full script it will help you to see the problem

          [CODE=javascript]
          var all_divs = document.getEle mentsByTagName( "a");

          var onload_init = {
          xCord : 0,
          yCord : 0,

          body : function() {
          for (i = 0; i < all_divs.length ; i++) {
          if (all_divs[i].title) {
          addEvent(all_di vs[i], "mousemove" , this.onover);
          addEvent(all_di vs[i], "mouseout", this.onout);

          all_divs[i].setAttribute(" tooltip", all_divs[i].title);
          all_divs[i].removeAttribut e("title");
          }
          }
          },

          getCords : function(evt) {
          if (document.captu reEvents) {
          onload_init.xCo rd = evt.pageX;
          onload_init.yCo rd = evt.pageY;
          } else {
          onload_init.xCo rd = window.event.cl ientX;
          onload_init.yCo rd = window.event.cl ientY;
          }
          },

          createTooltip : function() {
          var div_element = document.create Element("div");
          div_element.set Attribute("id", "tooltip_bo x");
          div_element.sty le.visibility = "hidden";
          document.body.a ppendChild(div_ element);
          },

          onover : function(evt) {
          var tooltip_div = document.getEle mentById("toolt ip_box");
          onload_init.get Cords(evt);

          if (tooltip_div == null) onload_init.cre ateTooltip();
          tooltip_div.sty le.top = (onload_init.yC ord + 12) + "px"
          tooltip_div.sty le.left = (onload_init.xC ord + 12) + "px"
          tooltip_div.sty le.visibility = "visible";

          tooltip_div.inn erHTML = "";

          // here is the problem this.getAttribu te doesn't get text on ie
          var inner_text = this.getAttribu te("tooltip");
          var ctn = document.create TextNode(inner_ text);
          tooltip_div.app endChild(ctn);
          },

          onout : function() {
          var tooltip_div = document.getEle mentById("toolt ip_box");
          tooltip_div.sty le.visibility = "hidden";
          }
          };


          function load_page() { onload_init.bod y(); }
          addEvent(window , "load", load_page);

          function addEvent(object , eventType, do_function){
          if (object.addEven tListener){
          object.addEvent Listener(eventT ype, do_function, true);
          return true;
          } else if (object.attachE vent){
          var to_return = object.attachEv ent("on" + eventType, do_function);
          return to_return;
          } else {
          return false;
          }
          }
          [/CODE]

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            hmmm ... first you should move the line where you retrieve your 'all_divs' into the onload-object so that the dom is ready to use for it?

            could you try to alert innerHTML of the node instead of trying to retrieve the tooltip-attribute? does that work and is it the innerHTML of the correct node?

            i just cannot test it since i'm using a mac an so no IE :) ... so i think we have to make little steps towards the solution ...

            kind regards

            Comment

            • tader
              New Member
              • Sep 2007
              • 43

              #7
              script is working file now i just updated addEvent function to this

              [CODE=javascript]
              function addEvent(obj, type, fn) {
              if (obj.addEventLi stener) {
              obj.addEventLis tener(type, fn, false);
              return true;
              } else if (obj.attachEven t) {
              obj["e" + type + fn] = fn;
              obj[type + fn] = function() {
              obj["e" + type + fn]( window.event );
              }
              var treturn = obj.attachEvent ("on" + type, obj[type + fn]);
              return treturn;
              } else {
              obj["on" + type] = obj["e" + type + fn];
              }
              }
              [/CODE]

              so thx for your help anyway ;]

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                glad to hear you got it working ... :)

                but i'm just wondering whether the line:

                [CODE=javascript]var all_divs = document.getEle mentsByTagName( "a");[/CODE]
                always works? is it called onload or before? typically it is a little bit unreliable to retrieve dom-nodes during page load ... so it is better to do it after the page is fully loaded and so the dom too?

                kind regards

                Comment

                Working...