remove() lets you remove one specific element, or use a selector to remove only specific descendants of an element.
For example,
$('div li').remove()
will remove all <li>s that are a descendent of $myElement.
And
$myElement.remove()
will remove $myElement itself.
$('document').ready(function() {
$('#emptyTrash').click(function() {
//remove the element with id 'third-div'
$('#third-div').remove();
//remove all decendants of the element with id 'first-div'
//that have the class 'removeMe'; For this exercise put
//nothing in the actual remove() tag
$('#first-div .removeMe').remove();
});
});
Важно
Для указания ИД и класса объекта одновременно нужно отделить их пробелом:
$('#first-div .removeMe').remove();
_____________________________________________________________________________________
RemoveData()
removeData() takes a key as a parameter, and deletes the data value stored at that key.
$('div.square').removeData('jumpedPieces');
_____________________________________________________________________________________
:odd() :even()
:odd() -Поиск нечетных элементов, начиная с нуля.
:even() -Поиск четных элементов, начиная с нуля.
$("tr:odd").css("background-color", "#bbbbff"); $('#right li:odd').remove();
_____________________________________________________________________________________
JQuery Events
_____________________________________________________________________________________
Click()
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.
$('#clickMe').click(function(){
$("#changeMe").html("I have been changed");
});
_____________________________________________________________________________________
On()
Example with click:
$('#clickMe').on("click", function(){
alert("I have been clicked!");
});
$(document).on("ready", function(){
message = "iiiiii'm ready!";
alert(message);
});
_____________________________________________________________________________________