Skip to content

Latest commit

 

History

History
113 lines (95 loc) · 1.65 KB

element.md

File metadata and controls

113 lines (95 loc) · 1.65 KB

- Element

  • $:
// Can use string for selector
$('ul');
// Or some node
$(window);
  • find:
$('ul').find('li');
  • each:
$('ul li').each(function (el, i) {
  // do something
});
  • css:
// Set
$('ul').css('color', 'red');
$('ul').css({
  'color': 'red',
  'background-color': 'yellow'
});

// Get
$('ul').css('color');
  • text:
// Return text of each li
$('li').text();
// Set text for each li
$('ul').text('text');
  • html:
// Return inner html of each li
$('li').html();
// Set inner html for each li
$('ul').html('text');
  • next/prev:
// Return collection of next elements of each li
$('li').next();
// Return collection of prev elements of each li
$('li').prev();
  • outerHeight:
// Return height of li
$('li').outerHeight();

// Given the margins
$('li').outerHeight(true);
  • outerWidth:
// Return width of li (given the margins)
$('li').outerWidth();

// Given the margins
$('li').outerWidth(true);
  • remove:
// Remove each li
$('li').remove();
  • position:
// Position
$('li').position();
  • offset:
// Position relative to viewport
$('li').offset();
  • append/prepend:
// Insert html in each li at the beginning
$('li').prepend('<div class="block"></div>');
// Insert html in each li at the end
$('li').append('<div class="block"></div>');
  • scrollTop:
// Get
$('li').scrollTop();
$(window).scrollTop();

// Set
$('li').scrollTop(100);
$(window).scrollTop(100);