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

Next Office Hours Session: "SVG" Oct 14 - 6:30 PM Eastern
Get a free trial // Grow your CSS skills // Land your dream job

jQuery variable

  • # May 8, 2013 at 8:20 am

    In this Codepen: 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

    1000 thx ……. :-)

Viewing 4 posts - 1 through 4 (of 4 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