Domanda

So, heres some code:

<!DOCTYPE html>
<html>
<head><title></title>
<script language = 'Javascript' type = 'text/javascript' src = 'jquery-1.10.2.js'></script> // jquery link there
<script language = 'Javascript' type = 'text/javascript'>

$(function() {

  $('#div1').mousedown(function(event) { $(this).css(bla).css(bla) });
  $('#div2').mousedown(function(event) { $(this).css(blah).css(blah) });

}); // end document.ready

</script></head>
<body>

<div id = 'div1' style = 'position: absolute; left: 50px;
top: 50px; z-index: 2; width: 50px; height: 50px; margin: 0px; padding: 0px;
border: 1px blue solid;'>Here</div>

<div id = 'div2' style = 'position: absolute; left:30px;
top: 50px; z-index: 1; width: 200px; height: 200px; margin: 0px; padding: 0px; 
border: 1px blue solid; background-color: blue;'></div>

</body>
</html>

It's important that the divs are positioned relative to the body, so I'm not encasing one within the other. However, I would be clicking on both divs at the same time. How do I get the mousedown event to fire first on #div1, then on #div2, without placing the second div inside the first? (Or vice versa). I get the feeling that it is quite simple so forgive my stupidity. If doing this somehow isn't possible, is there a way to synthesize the #div2 event anyway with jquery? Thanks.

È stato utile?

Soluzione

you can use something like

      $('#div1').mousedown(function(event) { $(this).css(bla).css(bla); $('#div2').mousedown(); });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top