10 examples of 'jquery toggle class onclick' in JavaScript

Every line of 'jquery toggle class onclick' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1function onClickToggleElement() {
2 var $el = $(this),
3 $showTarget = $($el.data('show')),
4 $hideTarget = $($el.data('hide')),
5 timeout = $el.data('timeout') || 0;
6
7 setTimeout(
8 function toggleHiddenClass() {
9 $showTarget.removeClass('hidden');
10 $hideTarget.addClass('hidden');
11 },
12 timeout
13 );
14}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

8function toggle(_btn, _div) {
9 var elem = document.getElementById(_div);
10
11 if(elem.style.display === 'none') {
12 elem.style.display = 'block'
13 _btn.innerHTML = "-";
14 }
15 else {
16 elem.style.display = 'none'
17 _btn.innerHTML = "+";
18 }
19}
10function toggle(toggleId)
11{
12 var toggle = document.getElementById ? document.getElementById(toggleId) : document.all[toggleId];
13 toggle.textContent = toggle.innerHTML == '\u25b6' ? '\u25bc' : '\u25b6';
14}
1029function toggle(id, $link) {
1030 $node = document.getElementById(id);
1031 if (!$node)
1032 return;
1033 if (!$node.style.display || $node.style.display == 'none') {
1034 $node.style.display = 'block';
1035 $link.innerHTML = 'Hide source ≢';
1036 } else {
1037 $node.style.display = 'none';
1038 $link.innerHTML = 'Show source ≡';
1039 }
1040}
46function toggle (event:any) {
47 // ignore the event if a key different from ENTER was pressed.
48 if (event.type === 'keypress' && event.which !== 13) {
49 return false;
50 }
51
52 const target = $(event.target);
53 const targetList = target.closest('ul.-with-hierarchy > li');
54 targetList.toggleClass('-hierarchy-collapsed -hierarchy-expanded');
55 return false;
56}
75toggle: function toggle(elem, callback) {
76 // Initialise a 'toggle' control
77 $(elem).click(function() {
78 if($(elem).hasClass("pressed")) {
79 $(elem).removeClass("pressed");
80 } else {
81 $(elem).addClass("pressed");
82 }
83 if(callback) {
84 return callback($(elem).hasClass("pressed"));
85 }
86 });
87},
25static toggle () {
26 const $container = $(this).closest('.js-toggle-container');
27 const $content = $container.find('.js-toggle-content');
28 if ($content.hasClass('display-none')) {
29 ToggleElement.show($container);
30 } else {
31 ToggleElement.hide($container);
32 }
33}
25function toggle(selector) {
26 getListItem(this).find(selector).toggle();
27}
11function jQueryToggle(event) {
12 var $toggle = $(event.target),
13 $content = $toggle.parent('.component').find('.content');
14 $content.slideToggle(200);
15}
34onclick: function onclick(e) {
35 jQuery(this).closest('.form__field-description').parent().find('.toggle-content').toggle();
36 return false;
37}

Related snippets