Jump to content

some problem


donaldunca

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...