Patrioticcow
Patrioticcow

Reputation: 27058

jquery, trigger a link click with another click problem?

i have this situation. I am using a simple tab menu from here.

<ul class="tabs">
<li><a href="#tab1">tab1</a></li>
<li><a  id="myprofile" href="#tab2">tab2</a></li>
</ul>

<div id="tab1" class="tab_content">
text    
</div>
<div id="tab2" class="tab_content">
text    
</div>

so far so good.

What i want to do is to trigger #myprofile from another link:

<a id="my_profile" href="" title="My Profile">My Profile</a>

I am trying to use something like this:

$('#my_profile').click(function() {
// $('#myprofile').click(); // this works
$('#myprofile').trigger('click'); // this works also
});

What happens is that when i click on the new link #my_profile, i go to the second tab for like 2 seconds then i get redirected to the first tab. But if i click on the tabs it works just fine.

if i use jsfiddle i get a {"error": "Please use POST request"} error: see here, but not on my page.

any ideas?

thanks

Upvotes: 0

Views: 496

Answers (2)

user405398
user405398

Reputation:

If you are using jquery tabs. Just try this,

$('#my_profile').click(function() {
   $(tabContainerSelector).tabs( "option", "selected", 1 );
});

See this.

Upvotes: 1

K6t
K6t

Reputation: 1845

try this once

<a id="my_profile" href="#" title="My Profile">My Profile</a>

Upvotes: 1

Related Questions