Monday, August 26, 2013

jQuery add class based on page URL


Jquery

$(function(){ function stripTrailingSlash(str) { if(str.substr(-1) == '/') { return str.substr(0, str.length - 1); } return str; } var url = window.location.pathname; var activePage = stripTrailingSlash(url); $('#left-nav ul li a').each(function(){ var currentPage = stripTrailingSlash($(this).attr('href')); if (activePage == currentPage) { $(this).addClass('active'); } }); });

Wednesday, August 21, 2013

Target only Safari and Chrome with CSS

CSS

@media screen and (-webkit-min-device-pixel-ratio:0) {

#title {
color: red !important;
}
}

Friday, August 16, 2013

set margin for span tag

CSS

display:inline-block

span is an inline element, not a block element, and they don't respect margin. You can use padding or make the span display:inline-block; and then use margins.

Jquery load with fadeout effect

HTML

Jquery

$(document).ready(function(){
  $('li a').click(function(){
   var url = $(this).attr("href");
    $('#container').fadeOut('slow', function(){
    $('#container').load(url, function(){
    $('#container').fadeIn('slow');
   });
  });
});
});

Javascript find highest and lowest from the given inputs

function highAndLow(numbers){ // numbers = "4 5 29 54 4 0 -214 542 -64 1 -3 6 -6"   let numbersInArr = numbers.split(' '...