开发者

Can I execute javascript on an element that is inside ui.selectable element?

开发者 https://www.devze.com 2023-03-28 03:21 出处:网络
As the title says: can I execute javascript onclick on an dom element that is inside jQuery\'s ui.selectable dom element.

As the title says: can I execute javascript onclick on an dom element that is inside jQuery's ui.selectable dom element.

I hope it's clear where the problem is. The div inside my selectable div cannot be clicked because it inherits its parent elements selectable property.

I tried sth like this:

<script type="text/javascript">

$("#myInnerDiv").click(function(event){
    event.stopPropagation();   
    /*event.stopImmediatePropagation();*/
    alert("drek");
});

</script>

<div id="selectable">
   <div id="myInnerDiv">
       <!-- here is where I am clicking and Alert is Not showing up -->
   </div>
</div>

It doesn't work. I'm 开发者_运维知识库stuck here for three days now and would greatly appreciate any suggestions!


You need to wrap your javascript in a $(function() {}); call:

$(function() { 
$("#myInnerDiv").click(function (event) {
    event.stopPropagation();
    /*event.stopImmediatePropagation();*/
    alert("drek");
});

});

or you can put the script block after the HTML.

0

精彩评论

暂无评论...
验证码 换一张
取 消