maria maria - 6 months ago 11
Javascript Question

jQuery execute on click not on input

Im currently doing an

onclick
event, where the user is redirected to a new site.

Unfortunly, when I click on the input located in class
side
, it fires the event, while im acually looking for it to not do the event while clicking / typing in the input field.

Q: How can I make the jQuery code not fire when clicking on the input field?

<div id="<?echo $ar['url'];?>" class="mobile-no-margin upgradeable full-mobile col-sm-12" style=" background-size: 100% 100%; background-image: url(test">
<div class="side">
<input type="input" name="<? echo $ar['input'];?>" class="col-sm-12">
</div>
</div>


jQuery code:

<script type="text/javascript">
$(".upgradeable").on('click',function(e) {
id = $(this).attr('id');
url(id);
});
</script>

Answer

Use

$(".upgradeable").on('click',function(e) {
var target = $( e.target );
  if ( !target.is( ".side" ) ) {
        id = $(this).attr('id');
        url(id);
    }
});
Comments