Hi Everyone,
I'm running into a problem with jquery live event binding on a link. When the link is added to the page it works fine, however when another link is added to the unordered list it requires two clicks for the click event to fire on either link. Any ideas?
$("div#website-messages ul li a").live("click", function() {
var link = $(this);
changeTab(link.attr("href"));
$(link.attr("title")).focus();
return false;
});
EDIT: OK I've narrowed down the problem. If I take out return false, the event fires every time. The problem is then the page jumps to the top. Any ideas to stop that?
Code that creates the links:
Validation.validate = function() {
var html = "";
for (var i = 0; i < errors.length; i++) {
html += "<li><a href='" + errors[i].tabid + "' title='" + errors[i].elementID + "'>" + errors[i].message + "</a></li>";
}
$("div#website-messages ul").html(html);
}
ChangeTab Function
function changeTab(changeTo) {
changeTo = changeTo.substr(changeTo.indexOf("#"), changeTo.length);
$("#tabs div").hide();
$(changeTo).show();
$("ul.navigation li a").removeClass("selected");
$("ul.navigation li a[href='" + changeTo + "']").addClass("selected");
}
SOLVED I had a blur event on the text inputs that were being focused to that validated them. If I clicked on one of the errors and focused to the first textbox, then clicked on the second error, it would focus to the second textbox but fire the blur event and not focus. Thank you all SO much for your help and suggestions, this was driving me crazy all day.