javascript - disabling onclick functionality parent/child container in jquery -


i want overrule onclick on parent div, when image-link in child container clicked.

i using onlick on container called ".sight-title" to: - change class toggleclass("active"); - change content ajax call

initial state:

<div class="sight-title" id="s2851">   <div class="row1"></div>   <div class="row2"></div> </div> 

after clicking:

    <div class="sight-title active" id="s2851">    <div class="detail1">     <a class="wikilink" target="_blank" title="en.wikipedia.org/wiki/marollen" href="http://en.wikipedia.org/wiki/marollen"><img src="img/contact/culisite_wikipedia.png" border="0"></a>   </div>   <div class="detail2"></div> </div> 

when de parent ".sight-title" clicked again changes initial state.

but when class="wikilinks" clicked don't want onclick on parent container work.

jquery code: the else-part should disabled when class="wikilinks" clicked...

$(".sight-title").click(function () {                 var id=$(this).attr("id");                                                       $("#"+id).toggleclass("active");                                     if($(this).hasclass("active")){                     $("#"+id).html(ajax_load);                       $.get(                        loadurldetail+"?id="+id+'&arrondissement='+arrondissement,                        {language: "php", version: 5},                        function(responsetext){                            $("#"+id).html(responsetext);                        },                        "html"                       );                    } else {                     $("#"+id).html(ajax_load);                       $.get(                        loadurltitle+"?id="+id+'&arrondissement='+arrondissement,                        {language: "php", version: 5},                        function(responsetext){                            $("#"+id).html(responsetext);                        },                        "html"                       );                   }             }); 

use jquery's unbind: http://api.jquery.com/unbind/

$('a.wikilink').click(function() {     //do stuff     $('a.sight-title').unbind('click'); }); 

edit 2:

you may need use live instead if link doesn't exist when create click event.

$('a.wikilink').live('click', function() {     //do stuff     $('a.sight-title').unbind('click'); }); 

edit:

as side note, might want make use of jquery's load function rather gets , such.

i think you'll find makes life easier.

you should @ selectors. you're selecting same object you're on $("#"+id) instead of doing $(this).


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -