views:

54

answers:

2

Problem is solved, i made another stupid mistake in my code... sorry, thanks

example:

<div id="window1Header" class="windowHeader">
   Window 1 <a id="min1" class="minimize">[-]</a> <a id="max1" class="maximize">[+]</a>
</div>
<script>
    $(function() {

    $(".windowHeader").mousedown(function () { 
  $(this).parent().css({"border" : "#000 1px dashed"});
  $(this).parent().draggable({ containment: 'parent' });
 });
$(".windowHeader").mouseup(function () { 
  $(this).parent().css({"border" : "#ccc 1px solid"});
  setTimeout(function() {
   $(this).parent().draggable('destroy');
   }, 100);
 });

   $('#min1').click(function(e) {
     e.stopPropagation();
        $("#window1Body").hide().slideUp(500);
});
$('#max1').click(function(e) {
 e.stopPropagation();
        $("#window1Body").hide().slideDown(500);
});

    });
</script>

The outerdiv (window1Header) has a mousedown and up event and the 2 links (min1 and max1) have click-events. But clicking the links wil trigger the event binded to window1Header. How can i trigger the right events? I'm using the jquery library btw.

Any help is appreciated!

+2  A: 

Generally, use stopPropagation to prevent the event from bubbling to parent elements. E.g.:

$('.minimize').click(function(e) {
    e.stopPropagation();
    ...
});
karim79
mmm, it seems it never triggers the event so your solution does not solve it. I'll add some more code to my question to explain.
Overbeeke
Problem solved, it was a stupid mistake in my code that i made, thanks anyway
Overbeeke
A: 

You need to at least have an href="#" on your a tags otherwise the click event will never fire. Also, return false in the click events.

 $('#max1').click(function(e) {
    $("#window1Body").hide().slideDown(500);
    return false;
 });
smack0007
Thats not right. I placed the links outside the div and the events where triggered just fine. The problem is with the links being inside the div. The only thing fired when clicking the links is the event of the div, so its not bubbling up it fires the parent event right away.
Overbeeke