Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript target xlink:href with jQuery?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #44989
    scoot
    Member

    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.

    #136131
    scoot
    Member

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.