Grow your CSS skills. Land your dream job.

jQuery variable

  • # May 8, 2013 at 8:20 am

    Hi
    In this Codepen: http://codepen.io/MortenAndersen/pen/pvLlx I’m trying to copy the URL to another href

    How can I do this with a variable so all the urls are copied.
    Copy the URL to the same class name!

    # May 8, 2013 at 9:09 am

    Something like this:

    $(‘#kort a’).each(function() {
    var cl = this.parentNode.className;
    var href = $(‘.kort-nav .’ + cl + ‘ a’).attr(‘href’)

    this.href = href;
    });

    # May 8, 2013 at 9:21 am

    $ function returns collection of elements – a list. In your case it is one element list, but it’s still a list. You have to specify what element from the list you want to get. Use first() function and it shoud resolve your problem.

    like this:
    $(‘#kort .id1 a’).first().attr(‘href’,$(‘.kort-nav li.id1 a’).first().attr(‘href’));

    # May 8, 2013 at 9:33 am

    @CrocoDillon
    1000 thx ……. :-)

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

You must be logged in to reply to this topic.

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