tags:

views:

47

answers:

4

I have a div element, with img element in it.

onclick of div i make one function, and onclick on img - another. but when i click on img it make the first function too, because the img is in div element. so, i think, that if there were something like isClicked, onclick of div i can just verify, if img is Not clicked ...

(i can write a logic, and verify it by so,for example onclick of img i can add a class to somebody... but maybe there is a function for it?)

Thanks

Update:

<div class="left_expended" style="position: relative;">
    Լեզուներ
    <img src="images/new_page.gif" id="new_lang" title="Լեզու ավելացնել" />
</div>

and jquery

$(".left_expended").live('click', function(){
            $(this).addClass("left_collapsed");
            $(this).removeClass("left_expended");
            $(this).next("div .container").slideUp(400);
        });

        $("#new_lang").click(function()
        {
            alert("something");
        });

onclick of img it makes first function too.

+3  A: 

You can prevent the click on the <img> from going up to the <div> using event.stopPrpagation(), like this:

$("#new_lang").click(function(e) {
  alert("something");
  e.stopPropagation();  //don't bubble!
});

What happens normally is that events bubble, the click on the <img> "bubbles up" to the <div> afterwards...unless you stop it, which is exactly what .stopPropagation() does. This way anything activating your $("div").click(...) is anywhere inside except the image, because a click there wouldn't go up anymore, which seems to be what you're after :)

Nick Craver
perfect. Thanks;)
Syom
A: 

i think now, but you can add it adding this to your code:

$("div,img").click(function(e){$(this).addClass("isClicked");e.stopPropagation();});

and then, you can play with CSS or jQuery, with the class ".isClicked"

Hope that helped you ;)

CuSS
+1  A: 

http://api.jquery.com/bind/ talks a bit about how they work. In particular:

Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object.

Chris
A: 

Use stopPropagation in the click event for the img so it won't propagate further to the div click event. Also look at http://api.jquery.com/event.isPropagationStopped/.

Grz, Kris.

XIII