Consider following code snippet:

<div>
    <p class="foo">Something_1</p>
    <p class="bizz foo">Something_2</p>
    <p class="foo bizz">Something_3</p>
</div>
<script>
    $('div').has('p').css('color','red');
    $('p').is('.foo').css('color','green');
    $('p').last().css('color','blue');
</script>
What will be the colors of the <p> elements?
Explanation
Unlike other filtering methods, .is() does not create a new jQuery object. Instead, it allows you to test the contents of a jQuery object without modification.

    $('div').has('p').css('color','red'); // make all p elements to be red
    $('p').is('.foo').css('color','green'); // Uncaught TypeError and will stop the code execution
    $('p').last().css('color','blue');
That is why all <p> elements will have red color.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести