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
Обратная Связь
Продолжайте изучать
тесты по JavaScript
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты