Grow your CSS skills. Land your dream job.

target xlink:href with jQuery?

  • # May 22, 2013 at 6:42 pm

    Hi,

    I’m using this code to animate scrolling on all my anchor tags:

    $(‘a[href*=#]:not([href=#])’).click(function() {
    if (location.pathname.replace(/^//,”) == this.pathname.replace(/^//,”)
    || location.hostname == this.hostname) {

    var target = $(this.hash);
    target = target.length ? target : $(‘[name=’ + this.hash.slice(1) +’]’);
    if (target.length) {
    $(‘html,body’).animate({
    scrollTop: target.offset().top
    }, 1000);
    return false;
    }
    }
    });

    The code works great but I have some links in an SVG and it’s not targeting them. jQuery doesn’t seem to recognize the attribute “xlink:href”. Is there any way to accomplish this?

    Thanks in advance.

    # May 22, 2013 at 10:47 pm

    I fixed this myself with a workaround. For anyone that may search this in the future, I used

    onclick=”specialfunction()”

    instead of “xlink:href”. My function looks like:

    function specialfunction(){
    $(‘html,body’).animate({
    scrollTop: $(‘#target’).offset().top
    }, 1000);
    return false;
    }

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".