logo
down
shadow

Toggle other specific classes off when toggling one on


Toggle other specific classes off when toggling one on

By : Bill Owen
Date : November 22 2020, 02:42 PM
Any of those help You can massively improve your logic and DRY up your code with the use of common classes. Firstly, apply a common class to all the div elements you want to be clickable, in my example I user svgContainer:
code :
<div>
    <div id="svg1" class="svgContainer"></div>
</div>
<div>
    <div id="svg2" class="svgContainer"></div>
</div>
<div>
    <div id="svg3" class="svgContainer"></div>
</div>
$(".svgContainer").on("click", function () {
    $(this).toggleClass('highlight');
    $('.svgContainer').not(this).removeClass('highlight');
});
.svgContainer { 
    height: 60px;
    background-repeat: no-repeat;
}
#svg1 {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/teacher.svg");
}
#svg1.highlight {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/teacher-purple.svg");
}
#svg2 {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/student.svg");
}
#svg2.highlight {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/student-purple.svg");
}
#svg3 {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/support.svg");
}
#svg3.highlight {
    background-image: url("http://fdslive.oup.com/www.oup.com/elt/general_content/global/measuring_impact/images/svgs/support-purple.svg");
}


Share : facebook icon twitter icon
toggle specific divs that have two classes using checkboxes

toggle specific divs that have two classes using checkboxes


By : Krisztián Molnár
Date : March 29 2020, 07:55 AM
wish helps you I found your question a little confusing, but perhaps something like this is what you mean:
code :
$('input[type="checkbox"]').click(function() {
   $('div.' + $(this).attr('class')).toggleClass('hit'); 
});
<div class="hit""ModelName1"></div>
<div class="hit ModelName1"></div>
Toggle 3 classes onclick (Only toggling 2)

Toggle 3 classes onclick (Only toggling 2)


By : Tara Sasu
Date : March 29 2020, 07:55 AM
may help you . Are you trying to get the code to cycle through all three texts on three consecutive clicks? Because that's not what toggleClass does. toggleClass toggles one or more classes on or off.
As you can tell by this fiddle, clicking the link toggles both the border, the font size, and the italics class.
jQuery toggle function for toggling specific div (and not all div with same class name.)

jQuery toggle function for toggling specific div (and not all div with same class name.)


By : Manisston
Date : March 29 2020, 07:55 AM
I wish this helpful for you Change $content.slideToggle() to $(this).next().slideToggle() assuming that .content is always the next sibling of .toggle
EDIT: since it's not, what you can do is use the postids. I think it would be better to use the data-postid attribute instead of adding it to the id (or do both) so that you don't have to parse it from the ID.
code :
$(".content[data-postid=" + $(this).data('postid') + "]").slideToggle();
Using jQuery to toggle specific classes [misleading?]

Using jQuery to toggle specific classes [misleading?]


By : Yury Gaydov
Date : March 29 2020, 07:55 AM
hope this fix your issue I have three article tags that each have 1 section which I need to animate to appear i.e height from 0px to whatever px. Each article has an ID what is the most efficient way to have an on click event for each one without writing a separate function for each individual id i.e is there a 'get clicked article's id' type method? , This is what I would do,
jQuery:
code :
$('.art h1').on('click', function() {
   $(this).parent().find('p').stop(true).slideToggle(); 
});
<div class="art">
    <h1>Some article stuff</h1>
    <p>text goes here</p>
</div>
$('.art h1').on('click', function() {    
    $('.art p').slideUp();
    $(this).parent().find('p').stop(true).slideToggle(); 
});
Toggle two classes on one element while not toggling a sibling element

Toggle two classes on one element while not toggling a sibling element


By : David Angel
Date : March 29 2020, 07:55 AM
may help you . In my document, I have two elements. The contents of those elements are hidden upon loading. When a user clicks the title or the plus symbol of that element it displays the contents. At the moment, when an element is displaying the contents, if a user click anywhere in the document, it closes what ever element that's open. I don't know what's causing that problem. , This is your problem, I commented the wrong line:
code :
$(function() {
  var title = new DropDown($('.title'));
  $(document).click(function() {
    //$('.drop').removeClass('active');
  });
});
span.rotate{
  -moz-transform:rotate(-90deg);
  -webkit-transform:rotate(-90deg);
  -o-transform:rotate(-90deg);
  -ms-transform:rotate(-90deg);
  position: absolute;
}
$(document).ready(function() {
  $rotated = false;
  $('.plus, .title').click(function() {
    $(this).toggleClass('rotateOn');
    $(this).children('span').toggleClass('rotate');
  });
});
$(function() {
  function DropDown(element) {
    this.title = element;
    this.initEvents();
  }

  DropDown.prototype = {
    initEvents: function() {
      var obj = this;
      obj.title.on('click', function(event) {
        $(this).parent().next('.drop').toggleClass('active');
        event.stopPropagation();
      });
    }
  }

  $(function() {
    var title = new DropDown($('.title'));
    $(document).click(function() {
      //$('.drop').removeClass('active');
    });
  });

  $(document).ready(function() {
    $rotated = false;
    $('.plus, .title').click(function() {
      $(this).toggleClass('rotateOn');
      $(this).children('span').toggleClass('rotate');
    });
  });

});
body {
  margin: 0;
  padding: 0;
  background: #141516;
  font-family: "Source Sans Pro", Helvetica, sans-serif;
  font-weight: 400;
  line-height: 2.3rem;
  color: #b3b3b3
}

::selection {
  background: #00DE6F;
  color: #141516
}

a {
  color: inherit
}

a:hover {
  color: inherit
}

.container {
  max-width: 500px;
  margin: 0 auto
}

.main {
  margin: 0px
}

.main a {
  color: #fff;
  text-decoration: none;
  transition: all 0.2s ease-in-out
}

.main a:hover {
  color: #00DC73
}

.job {
  border-bottom: 1px solid #191919;
  padding-bottom: 15px
}

.job .drop {
  display: none;
  margin-top: 20px
}

.job .drop.active {
  display: block;
  margin-top: 20px
}

.rotateOn {
  transform: rotateZ(45deg)
}
span.rotate{
  -moz-transform:rotate(-45deg);
  -webkit-transform:rotate(-45deg);
  -o-transform:rotate(-45deg);
  -ms-transform:rotate(-45deg);
  position: absolute;
}
<script src="http://code.jquery.com/jquery-1.11.3.js"></script>

<div class="container">
    <div class="main">

        <div class="job 1">
            <h3>
                <a href="#" class="title">Job 1<span class="pull-right plus">+</span></a>
                <a href="#" class="btn btn-success btn-xs pull-right"></a>

            </h3>
            <div class="drop">
                <p class="clearfix">
                    Info
                </p>

                <p><strong>What you’ll do:</strong></p>
                <ul>
                    <li>info</li>


                </ul>

                <p><strong>What we’re looking for:</strong></p>
                <ul>
                    <li>info</li>

                </ul>

                <p><strong>Bonus points:</strong></p>
                <ul>
                    <li>info</li>
                </ul>


            </div>
        </div>
        <!-- //END -->

        <div class="job 2">
            <h3>
                <a href="#" class="title">Job 2<span class="pull-right plus">+</span></a>
                <a href="#" class="btn btn-success btn-xs pull-right"></a>

            </h3>
            <div class="drop">
                <p class="clearfix">
                    Info
                </p>

                <p><strong>What you’ll do:</strong></p>
                <ul>
                    <li>info</li>


                </ul>

                <p><strong>What we’re looking for:</strong></p>
                <ul>
                    <li>info</li>

                </ul>

                <p><strong>Bonus points:</strong></p>
                <ul>
                    <li>info</li>
                </ul>


            </div>
        </div>
        <!-- //END -->

    </div>
</div>
Related Posts Related Posts :
  • How to increase jqgrid header checkbox size
  • Compile directive within controller and return html to DataTable's render function
  • how to change each consecutive div order?
  • Replace submit button value with ASCII character
  • Make mmenu expand to the current url
  • Uncaught TypeError: "#submitRates".click is not a functio
  • ACF Tag It Field and createTag
  • Original filename in case of error in jQuery File Upload
  • Cycle through an HTML list with jinja and jQuery?
  • jQuery Ajax triggering 2 events together from single click
  • jQuery UI draggable and sortable not working
  • jquery access dynamically generated form
  • Typeahead - Unable to use dynamically created array as source of data
  • Changing aria-label for ascending and descending states on a sortable table with Jquery
  • Sending var with load jquery
  • How to wrap all siblings in one class after a class? (jQuery)
  • Appending an object to serialized form data
  • how to replace jquery to jquery mobile
  • jquery show/hide buttons on same row not showing pretty - causing half hight during animation?
  • <select> change event doesn't work
  • jQuery hover/click on desktop and mobile devices
  • Use Jquery and FormData to submit form fields and uploaded File to Spring MVC Controller in Spring Boot App
  • Is there a smart way to simplify these jquery codes?
  • JQuery File Upload middleware - Image versions not creating
  • How to increase cookies storage limit(4096) in chrome
  • div on translating increases page width
  • How do I set shipping value depending on select & checkbox
  • jQuery change active state of multiple elements on page when different categories are selected
  • rails jquery script does not work when clicking link
  • Array of JQuery Selectors
  • how can I target with jquery this element?
  • Display default date based on time in jquery datepicker
  • Changing date format before binding JSON data to a jquery template
  • How to use load and open in same div
  • How to make position fixed div scroll horizontally?
  • save state the list on page refresh
  • Change the value of many Divs on select of drop-down
  • Background-image transition not working
  • http request inside another http request success response not working in jquery
  • jQuery hover is not working when I use display:none property of my input
  • Limit jQuery toggle to only affect one accordion
  • Changing div values when dropdown is selected
  • How to replace a list of images with jQuery?
  • jQuery Clone / Copy Style attributes of first td of Table to another Tables's first td
  • Why my select only get the last value?
  • fullpage.js multiple onLeave and afterLoad events
  • Insightly CRM Ajax API proxy
  • Highlighting the Menu Item for the Current Page Wordpress
  • Value change event is not firing in jquery
  • Add text after first element
  • My generic click event for anchors doesn't work
  • jQuery append - what am I doing wrong?
  • how to align jqgrid 4.10 column headers and data
  • Make image stay where it is
  • Rails jQuery-autocomplete client-side
  • Create array from xml nodes using jquery
  • Simple jQuery Each Function
  • multiple selectors with .removeAttr
  • How to automatically input a value in a text box based on another and vice versa?
  • Apply hover-effect on transparent parts of SVG
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co