Select the correct span and div in jquery using classes

user1689274

I am trying to create a navigation that will collapse on click. It is working, but I want to only select the set clicked.

<div class="sidenav-set">
    <a href="javascript:void(0)" onclick="toggleSet()" class="sidenav-set-link">Apply<span class="glyphicon glyphicon-chevron-down"></span></a>
    <div class="sidenav-links">
      <a href="#">About</a>
      <a href="#">Services</a>
      <a href="#">Clients</a>
      <a href="#">Contact</a>
    </div>
  </div>
  <div class="sidenav-set">
    <a href="javascript:void(0)" onclick="toggleSet()" class="sidenav-set-link">Information <span class="glyphicon glyphicon-chevron-down"></span></a>
    <div class="sidenav-links">
      <a href="#">About</a>
      <a href="#">Services</a>
      <a href="#">Clients</a>
      <a href="#">Contact</a>
    </div>

The jquery I have is this:

function toggleSet() {
  $(".sidenav-set-link span").toggleClass("glyphicon-chevron-down glyphicon-chevron-up")
  $(".sidenav-links").toggle('slow')
}

This works, but it operates on all the sets. I want to click the link a the top of a set, change out the class on the up/down arrow and show/hide the set of .sidenav-links

I've tried several things that have not worked, any help would be greatly appreciated.

Thanks in advance.

Joundill

You want to use $(this) and a selector to find the elements you want to modify.

function toggleSet() {
  $(this).find("span").toggleClass("glyphicon-chevron-down glyphicon-chevron-up");
  $(this).parents(".sidenav-set").find(".sidenav-links").toggle('slow');
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to select span element inside multiple div classes and id's?

From Dev

Finding correct SPAN tag using jQuery prev() and next()

From Dev

Extjs Progressbar in span/div is not correct

From Dev

How to select a span with a text inside a div using CSS?

From Dev

Span dropdown select Jquery

From Dev

Add decimal value to div classes using jQuery

From Dev

Selenium Python Xpath how to select the correct span text from many nested div tags

From Dev

How do I select a span content, using jquery?

From Dev

Hide element if span element inside a div tag is empty using jquery

From Dev

clear form element values within specific div or span using jquery

From Dev

Hide element if span element inside a div tag is empty using jquery

From Dev

What is the correct approach to adding classes to an array of DOM objects using jQuery?

From Dev

wrap $ in span using jQuery

From Dev

select currently focused contenteditable div using jquery

From Dev

How to Select 'id' attribute of a <div> using jQuery

From Dev

How to select a particular part of the div using jQuery?

From Dev

select currently focused contenteditable div using jquery

From Dev

Hiding div using jQuery and select onchange persistently

From Dev

JQuery select multiple classes

From Dev

Using 2x classes to select and toggle a third with jQuery

From Dev

How to add classes to div using jquery in sequence like animation

From Dev

Using jQuery.html method to set a Div to a Rails link_to with a span

From Dev

Count all div elements and add each number inside span using jQuery

From Dev

jquery to get href in anchor tag using div/span ID selector and anchor tag class

From Dev

How to change CSS of child element <span> inside parent <div> element Using jQuery onclick event?

From Dev

How add a span after innerhtml text inside a div using jQuery or javascript?

From Dev

How to get a span from a div by span text in jquery

From Dev

how to select span with jquery in a finded class?

From Dev

How to Select a price with jQuery or Regex within a span?

Related Related

  1. 1

    How to select span element inside multiple div classes and id's?

  2. 2

    Finding correct SPAN tag using jQuery prev() and next()

  3. 3

    Extjs Progressbar in span/div is not correct

  4. 4

    How to select a span with a text inside a div using CSS?

  5. 5

    Span dropdown select Jquery

  6. 6

    Add decimal value to div classes using jQuery

  7. 7

    Selenium Python Xpath how to select the correct span text from many nested div tags

  8. 8

    How do I select a span content, using jquery?

  9. 9

    Hide element if span element inside a div tag is empty using jquery

  10. 10

    clear form element values within specific div or span using jquery

  11. 11

    Hide element if span element inside a div tag is empty using jquery

  12. 12

    What is the correct approach to adding classes to an array of DOM objects using jQuery?

  13. 13

    wrap $ in span using jQuery

  14. 14

    select currently focused contenteditable div using jquery

  15. 15

    How to Select 'id' attribute of a <div> using jQuery

  16. 16

    How to select a particular part of the div using jQuery?

  17. 17

    select currently focused contenteditable div using jquery

  18. 18

    Hiding div using jQuery and select onchange persistently

  19. 19

    JQuery select multiple classes

  20. 20

    Using 2x classes to select and toggle a third with jQuery

  21. 21

    How to add classes to div using jquery in sequence like animation

  22. 22

    Using jQuery.html method to set a Div to a Rails link_to with a span

  23. 23

    Count all div elements and add each number inside span using jQuery

  24. 24

    jquery to get href in anchor tag using div/span ID selector and anchor tag class

  25. 25

    How to change CSS of child element <span> inside parent <div> element Using jQuery onclick event?

  26. 26

    How add a span after innerhtml text inside a div using jQuery or javascript?

  27. 27

    How to get a span from a div by span text in jquery

  28. 28

    how to select span with jquery in a finded class?

  29. 29

    How to Select a price with jQuery or Regex within a span?

HotTag

Archive