donaldunca Posted April 3, 2008 Share Posted April 3, 2008 I have some problem to understand code in javascript. I don't understand some code: event.cancelBubble=true; function ItemMinimize(Name) {var MItem=document.all(''.concat(Name)); //MItem=eval(MItem);if (MItem.style.display==''){MItem.style.display='none';} else {MItem.style.display='';} } It has some difference between Firefox and Opera. I run a webpage by Firefox, it will have different result in Opera.Could you help me? Thank for advanced. Link to comment Share on other sites More sharing options...
Synook Posted April 3, 2008 Share Posted April 3, 2008 event.cancelBubble=true; This stops the event from "bubbling" up (or was it down?) the DOM tree - that is, being detected by elements parent to the element that triggered the event. Patchy support from non-IE browsers, they use stopPropagation(). function ItemMinimize(Name) {var MItem=document.all(''.concat(Name)); //MItem=eval(MItem);if (MItem.style.display==''){MItem.style.display='none';} else {MItem.style.display='';}} This basically will set the element's style to display:none if it is not so, and to blank if it is none. document.all has bad support, which is why you may have trouble in some browsers. document.getElementById() is the replacement function ItemMinimize(Name) { var MItem = document.getElementById(Name); if (MItem.style.display == '') MItem.style.display = 'none'; else MItem.style.display = '';} Link to comment Share on other sites More sharing options...
jeffman Posted April 3, 2008 Share Posted April 3, 2008 event.cancelBubble=true; This stops the event from "bubbling" up (or was it down?) the DOM tree - that is, being detected by elements parent to the element that triggered the event. Depends on your point of view. If you're looking at a DOM tree, the parents are "up," so "bubbling up" makes sense. But is, let's say, you're looking at a paragraph inside a div inside another div, the parents seem to go down, "closer to the page."I've noticed this the most with click events that caused responses I did not anticipate. CancelBubble, problem solved. Link to comment Share on other sites More sharing options...
donaldunca Posted April 4, 2008 Author Share Posted April 4, 2008 I will think about your saying. Thank for your helps Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.