Forums

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

Home Forums JavaScript jQuery variable

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44629
    Morten
    Participant

    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!

    #134436
    CrocoDillon
    Participant

    Something like this:

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

    this.href = href;
    });

    #134438
    Malgosia
    Participant

    $ 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’));

    #134441
    Morten
    Participant

    @CrocoDillon
    1000 thx ……. :-)

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.