/    Sign up×
Community /Pin to ProfileBookmark

anchor tag losses focus

Hi I am using jqury for my java script .

here my simple jquery

[CODE]
$(document).ready(function(){
$(“a.showHidePrograms”).live(‘click’, function(){
var $div= $(this).parent().next(“div”);
if($div.attr(“class”) == ‘hide’){
$div.attr(“class”,”show”);
}else{
$div.attr(“class”,”hide”);
}
$(this).focus();
});
});

[/CODE]

this just changes the class for the div element.

The problem is everytime I click on this link the browser goes to the top.
I mean If my page has vertical scroll bar ,and I pulled down the vertical scroll bar to see the bottom row of the table or I am at the last row , there if I click this link the browser goes to top again , what I want is if I click on the link I donot want browser to change it focus , please help me with this.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991May 04.2010 — The link is <a href="#"> I presume?

Then return false, to stop the link. I presume that if you put it at the end of the function there, jQuery will return false properly, there could be a jQuery function for it, I don't know.$(document).ready(function(){
$("a.showHidePrograms").live('click', function(){
// Code
return false;});
});

<a href="#" onclick="return false;"> or the unobtrusive version works for sure, I can't say for certain about jQuery.
×

Success!

Help @fachhoch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...