Cman
Cman

Reputation:

Jquery and Safari

I'm having an issue with JQuery and Safari (Windows Version). The code works on FF/IE7/Chrome but not Safari.

I have a simple <li> that has a <div> embedded in to - clicking the <li> should expose the hidden div, but not in Safari.

The HTML:

<ul>
<li>something</li>
<li>something2</li>
<li class="more">
        <a href="" class="moreFacetsLink">Click to see more options</a>
        <div class="moreFacets">bunch of text</div>
</li>
</ul>

Here is the JQuery code:


     $('.moreFacetsLink').click(function () {
$(this).siblings('div').toggle(); });

Any thoughts as to what may be going on here? Again - this seems to work on all other browsers!

I'm a newbie when it comes to JQuery.

Thanks!

Upvotes: 1

Views: 7937

Answers (4)

Edgar
Edgar

Reputation: 71

First you need to check if the browser is doing postback and if this is true you can avoid it like this

$('.moreFacetsLink').click(function (e) {
    e.preventDefault(); // this prevent postback

    $(e.target).siblings('div').toggle();
});

try this: $(e.target) instead of this $(this)
this could be a different way

hope this helps

Upvotes: 0

Scott Rippey
Scott Rippey

Reputation: 15810

I'm pretty sure you need to return false; from the click function to cancel the link click.

Upvotes: 0

cobbal
cobbal

Reputation: 70733

href="" is reloading your page in safari
I would try using css to underline and style it, and drop the empty href.

Upvotes: 0

Pseudo Masochist
Pseudo Masochist

Reputation: 1927

How accurate is your HTML pasting?

You never closed your "moreFacetsLink" anchor tag, which probably makes Safari think that it was implicitly closed, and the "bunch of text" is surrounded by an additional, HREF-less Class-less Unclosed anchor tag... evidenced by the fact that this:

$(".moreFacetsLink").click(function () {
    $(this).siblings("a").children("div").toggle();
});

... does what you want with your submitted markup.

Close off your anchor tag properly (bonus points for including the href attribute) and you should be good to go.

Upvotes: 1

Related Questions