Forums

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

Home Forums JavaScript Working on one element, not on another.

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #166074
    deeve007
    Participant

    This works:

    $(“.menu-toggle”).click(function(){
    $(“.more-news”).toggle();
    return false;
    });

    This doesn’t:

    $(“.more-news”).click(function(){
    $(“.more-news”).toggle();
    return false;
    });

    The trigger element is a link in both cases. What could I be looking for to explain why one is working and another not?

    #166077
    Alen
    Participant
    $('.more-news').click(function(){
      $(this).toggle();
    });
    

    $(this) is current referenced item. If you had more than one link on the page this refers to the element being interacted with (clicked).

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.