Tags » JQuery

How To Start Writing Code

For those who are at the beginner stage of their software development career, there are challenges that some face when it comes to breaking down a problem into more manageable steps. 139 more words

Blog

Toggling More Than Two Classes


A


B

Calling Function on Click

$('.box').on('click', e => {
  $(e.target).toggleClasses([
    'myClass1',
    'myClass2',
    'myClass3',
    'myClass4'
  ], true);
});

Main Function

$(function(e) {
  e.fn.extend({
    toggleClasses: function(t, r) {
      var o = {
          toggleZero: r
        },
        n = 0,
        s = e(this).attr("class").split(" "),
        i = [];
      Array.prototype.remove = function() {
        for (var e, t, r = arguments, o = r.length; o && this.length;)
          for (e = r[--o]; - 1 !== (t = this.indexOf(e));) this.splice(t, 1);
        return this
      };
      for (var u = 0; u < t.length; u++) - 1 != s.indexOf(t[u]) && (i[u] = "true");
      for (var a = 0; a < t.length; a++) { if (!(i.indexOf("true") >= 0)) {
          n = 0, s.push(t[n]);
          break
        }
        if ("true" === i[a] && a < t.length - 1) { s.remove(t[a]), n = a + 1, s.push(t[n]); break } if ("true" === i[a]) { s.remove(t[a]), n = 0, t.length > 1 && o.toggleZero !== !0 && s.push(t[n]);
          break
        }
      }
      return e.extend(o, t), e(this).each(function() {
        e(this).attr("class", s.join(" "))
      })
    }
  });
});
… 23 more words
JQuery

Set Image URL Using Data Attribute

Use: data-imgsrc=”image url here”

$('').each(function() {
	var t = $(this).data('imgsrc'),
	tag = $(this).attr('src');
	if(tag){
	     $(this).attr('src', t);
	}else{
	     $(this).css({
		'background-image': 'url(' + t + ')'
	     });
	}
});
… 66 more words
JQuery

Get current date in JQuery

new Date().getDate()          // Get the day as a number (1-31)
new Date().getDay()           // Get the weekday as a number (0-6)
new Date().getFullYear()      // Get the four digit year (yyyy)
new Date().getHours()         // Get the hour (0-23)
new Date().getMilliseconds()  // Get the milliseconds (0-999)
new Date().getMinutes()       // Get the minutes (0-59)
new Date().getMonth()         // Get the month (0-11)
new Date().getSeconds()       // Get the seconds (0-59)
new Date().getTime()          // Get the time (milliseconds since January 1, 1970) 226 more words

jQuery Reference Notes

The output of a jquery selection is a javascript array, so you can do array manipulations on it like:
var elem = $(“p”);
This gives all the… 521 more words

Javascript

How to create custom accordions using jQuery?

The accordion is one of the useful elements. Accordion shows only one collapsible item at a time. But most importantly, an accordion shortens pages and reduce scrolling of the website.  188 more words

Technology