The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

target xlink:href with jQuery?

  • # May 22, 2013 at 6:42 pm


    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) {
    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


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

    function specialfunction(){
    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.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed