I am using JQuery 1.4.2, below code was working before with JQuery 1.3, can you please suggest what is issue with the below code as if I comment this code then there is no error coming on page.
$(".load-control").each(function()
{
var $objThis = $(this);
var fname = $objThis.attr("href");
($objThis).bind("click",false); //Removing the attached click eve开发者_JS百科nt
});
Please suggest!!
Use unbind
to remove handlers:
$(".load-control").each(function()
{
var $objThis = $(this);
var fname = $objThis.attr("href");
$objThis.unbind("click"); //Removing the attached click event handler
});
The above will remove all click
handlers from the element. If you just want to remove the specific one you set earlier, you can do that, e.g.:
// Earlier, when setting up
$(".load-control").each(function()
{
$(this).click(handleLoadControlClick);
});
// The unhooking code you quoted
$(".load-control").each(function()
{
var $objThis = $(this);
var fname = $objThis.attr("href");
$objThis.unbind("click", handleLoadControlClick); // Remove that specific handler
});
// The handler
function handleLoadControlClick(event) {
// ...
}
More in the docs linked above.
(Off-topic: The parens around $objThis
in your bind
call served no purpose, so I removed them.)
try ($objThis).bind("click",function(){return false;});
or undind function
Try unbind function $($objThis).unbind("click")
精彩评论