Difference between revisions of "Selecting Elements"

From rbachwiki
Jump to navigation Jump to search
Line 33: Line 33:
  var $copy = $group.find('input:last').clone();
  var $copy = $group.find('input:last').clone();
  $group.append($copy);
  $group.append($copy);
---
--
[[#top|Back To Top]]-[[JQuery|Category]]-[[Main_Page| Home]]
[[#top|Back To Top]]-[[JQuery|Category]]-[[Main_Page| Home]]

Revision as of 19:07, 25 December 2016

Selecting DOM Elements

$('#idname')
$('.className')

Find any a tags contained within the selected tag

$('#idname').find('a')

Find Children of tag

$('#idname').children()
$('#idname').children('h2')

Select Parents

$('#idname').parents()

Siblings

$('#idname').siblings()

Adding and Removing Classes

  $('body').addClass('js');

    var $circles = $('#circles');

    $circles.find(':nth-child(2)')
        .addClass('selected');

    $circles.find(':nth-child(4)')
        .removeClass('selected');

    $circles.find(':nth-child(4)')
        .toggleClass('selected');

Cloning DOM Elements

var $group = $('#group-friends');
var $copy = $group.find('input:last').clone();
$group.append($copy);

-- Back To Top-Category- Home