29.07.2016 Views

front-end-developer_1_

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Front-End-Developer - Level 1<br />

Insert before or after a DOM element:<br />

$('p').before('Title for paragraph');<br />

$('h1').after('New subheading');<br />

Remove a DOM element:<br />

$('#id-to-remove').remove();<br />

Select the children of a DOM element:<br />

$('.some-class').children(); //select all children<br />

$('ul').children('li'); // selects just the s<br />

Select only the first or last child element for a node:<br />

$('ul').children('li').first();<br />

$('ul').children('li').last();<br />

Select the element that was clicked on with this:<br />

$('.some-class').click(function() {<br />

});<br />

$(this);<br />

Test that you've selected the correct DOM element:<br />

$('.element-to-select').css('background-color', 'green');<br />

Test that you've properly attached an event handler:<br />

$('.element-to-select').click(function() {<br />

});<br />

alert('hi');<br />

DOM Manipulation and Traversal<br />

175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!