473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

ie getAttribute problems

43
Hi, so i done script like that

Expand|Select|Wrap|Line Numbers
  1.     body : function() {
  2.         for (i = 0; i < all_divs.length; i++) {
  3.             if (all_divs[i].title) {
  4.                 addEvent(all_divs[i], "mouseover", this.onover);
  5.                 addEvent(all_divs[i], "mouseout", this.onout);
  6.  
  7.                 all_divs[i].setAttribute("tooltip", all_divs[i].title);
  8.                 all_divs[i].removeAttribute("title");
  9.             }
  10.         }
  11.     }, 
  12.  
  13.     onover : function() {
  14.         var msger = document.getElementById("msger");
  15.         msger.innerHTML = this.getAttribute("tooltip");
  16.     },
  17.  
So firefox prints out tooltip but the ie6 doesn't so what should i do that ie would print tooltip attribute
Mar 22 '08 #1
7 2208
gits
5,390 Expert Mod 4TB
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
Mar 22 '08 #2
tader
43
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.getAttribute("tooltip"); it doesn't work on ie on ff everything is ok. I need it to work on this.
Mar 23 '08 #3
gits
5,390 Expert Mod 4TB
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:

Expand|Select|Wrap|Line Numbers
  1. all_divs[i].tooltiptext = 'your_text';
  2.  
and later on retrive it with:

Expand|Select|Wrap|Line Numbers
  1. this.tooltiptext;
kind regards
Mar 23 '08 #4
tader
43
hm... that didn't work dam it ;] mabey if i give you full script it will help you to see the problem

Expand|Select|Wrap|Line Numbers
  1. var all_divs = document.getElementsByTagName("a");
  2.  
  3. var onload_init = {
  4.     xCord : 0, 
  5.     yCord : 0,
  6.  
  7.     body : function() {
  8.         for (i = 0; i < all_divs.length; i++) {
  9.             if (all_divs[i].title) {
  10.                 addEvent(all_divs[i], "mousemove", this.onover);
  11.                 addEvent(all_divs[i], "mouseout", this.onout);
  12.  
  13.                 all_divs[i].setAttribute("tooltip", all_divs[i].title);
  14.                 all_divs[i].removeAttribute("title");
  15.             }
  16.         }
  17.     }, 
  18.  
  19.     getCords : function(evt) {
  20.         if (document.captureEvents) {
  21.             onload_init.xCord = evt.pageX;
  22.             onload_init.yCord = evt.pageY;
  23.         } else {
  24.             onload_init.xCord = window.event.clientX;
  25.             onload_init.yCord = window.event.clientY;
  26.         }
  27.     },
  28.  
  29.     createTooltip : function() {
  30.         var div_element = document.createElement("div");
  31.         div_element.setAttribute("id", "tooltip_box");
  32.         div_element.style.visibility = "hidden";
  33.         document.body.appendChild(div_element);
  34.     },
  35.  
  36.     onover : function(evt) {
  37.         var tooltip_div = document.getElementById("tooltip_box");
  38.         onload_init.getCords(evt);
  39.  
  40.         if (tooltip_div == null) onload_init.createTooltip();
  41.         tooltip_div.style.top = (onload_init.yCord + 12) + "px"
  42.         tooltip_div.style.left = (onload_init.xCord + 12) + "px"
  43.         tooltip_div.style.visibility = "visible";
  44.  
  45.         tooltip_div.innerHTML = "";
  46.  
  47.         // here is the problem this.getAttribute doesn't get text on ie
  48.         var inner_text = this.getAttribute("tooltip");
  49.         var ctn = document.createTextNode(inner_text);
  50.         tooltip_div.appendChild(ctn);
  51.     },
  52.  
  53.     onout : function() {
  54.         var tooltip_div = document.getElementById("tooltip_box");
  55.         tooltip_div.style.visibility = "hidden";
  56.     }
  57. };
  58.  
  59.  
  60. function load_page() { onload_init.body(); }
  61. addEvent(window, "load", load_page);
  62.  
  63. function addEvent(object, eventType, do_function){
  64.     if (object.addEventListener){
  65.         object.addEventListener(eventType, do_function, true);
  66.         return true;
  67.     } else if (object.attachEvent){
  68.         var to_return = object.attachEvent("on" + eventType, do_function);
  69.         return to_return;
  70.     } else {
  71.         return false;
  72.     }
  73. }
  74.  
Mar 23 '08 #5
gits
5,390 Expert Mod 4TB
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
Mar 23 '08 #6
tader
43
script is working file now i just updated addEvent function to this

Expand|Select|Wrap|Line Numbers
  1. function addEvent(obj, type, fn) {
  2.     if (obj.addEventListener) {
  3.         obj.addEventListener(type, fn, false);
  4.         return true;
  5.     } else if (obj.attachEvent) {
  6.         obj["e" + type + fn] = fn;
  7.         obj[type + fn] = function() { 
  8.             obj["e" + type + fn]( window.event ); 
  9.         }
  10.         var treturn = obj.attachEvent("on" + type, obj[type + fn]);
  11.         return treturn;
  12.     } else {
  13.         obj["on" + type] = obj["e" + type + fn];
  14.     }
  15. }
  16.  
so thx for your help anyway ;]
Mar 24 '08 #7
gits
5,390 Expert Mod 4TB
glad to hear you got it working ... :)

but i'm just wondering whether the line:

Expand|Select|Wrap|Line Numbers
  1. var all_divs = document.getElementsByTagName("a");
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
Mar 24 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mr_burns | last post by:
Hi, I have the following code that works fine except the getAttribute line: var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("note.xml"); nodes =...
3
by: hutch | last post by:
Hi, I'm making use of this VERY useful function for a so called 'standards compliant' replacement for target="_blank": function externalLinks() { if (!document.getElementsByTagName) return;...
6
by: Banski | last post by:
Hi, Im quite new to XML in .Net. Im getting values from an xml file using XPath and sorting as you see in the code below. I cant figure out how to get the value of date with GetAttribute. Hope...
2
by: DN | last post by:
This works: nav.GetAttribute("@ATTRIBUTE",""); This doesn't: string strTemp = "@ATTRIBUTE"; nav.GetAttribute(strTemp,""); Anybody know a way around this?
3
by: duff | last post by:
Hiya, I'm trying to replace the commented out code below with a neater version using the IAttributeAccessor interface (so that I don't have to write 'if' statements for all control types). At...
13
by: Noa | last post by:
Hi I have a page that looks like that: <form name="kuku1" action ="anotherpage.html" > <input name="name"> <input name="kuku2"> </form> As far as i know, "getAttribute" should return a...
2
by: christopher.secord | last post by:
I'm having a hard time understanding an error that I'm getting. In the code below, I'm trying to call substring() on an attribute of an anchor. The error I get says "getAttribute("rel") has no...
3
by: jphaycock | last post by:
Hi all I am trying to get a url attribute from an xml node: <item> <media url="http://blablabla.com" /> </item> I can do this in IE with the following code: var newDom =...
4
by: RobG | last post by:
I have always accessed attributes such as disabled using the DOM element property, however I was wondering about implementing a more generic function to get the values of attributes - which of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.