views:

28

answers:

3

this is my code :

<input type="button" value="edit" id="edit"/>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
    $('input').click(function(){
            alert('sss')
        })
    $('input').click(function(){
            alert('gggg')
        })
</script>

and when i click the button, it alert twitce,

so how to Cover the first Statement ,

thanks

A: 
$('input').click(function(){ 
        alert('gggg') ;
        return false;
    }) 

or

$('input').click(function(event){ 
        alert('gggg') ;
        event.stopPropagation();
    }) 

Now to completely get rid of that event handler, you could unbind it:

$('input').click(function(){
        alert('sss')
    });
// :
// :

$('input').unbind("click");
$('input').click(function(){
        alert('gggg')
    })
James Curran
I think the preferred jQuery way is to included an `event` in the function arguments then call `event.preventDefault();` rather than `return false;`
Hooray Im Helping
+1  A: 

You could use jQuery.unbind() method to remove any click event listener from specified elements and then bind a new one:

$("input").unbind("click").click(function() {
    alert("This is the only listener bound to this element");
});
Crozin
+3  A: 

Remove this from the <script> block

$('input').click(function(){
    alert('sss')
})

so that you are left with only

<input type="button" value="edit" id="edit"/>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
    $('input').click(function(){
        alert('gggg');
    });
</script>
Buggabill
Read the question title again. He cannot remove that line.
James Curran
If they cannot delete code from the file, how are they going to add to it?
Buggabill
can not remove it !!!!
zjm1126
I'm assuming that the lines are actually in two separate .JS files, one which he can modify, and one which he can't.
James Curran