Selects all elements with class "small" and all span elements with class "big" and sets 5px solid red border

<scripttype="text/javascript">

$(document).ready(function () {

$('.small,
span.big').css('border', '5px solid red');

});

</script>

Selects all elements with class small that are nested in a an element with id=div2 and sets 5px solid red border

<html>

<head>

<title></title>

<scriptsrc="Scripts/jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('#div2
.small').css('border', '5px solid red');

});

</script>

</head>

<body>

<divid="div1"class="small">

DIV 1

</div>

<br/>

<divid="div2">

Div 2

<br/>

<divclass="small">

DIV 3

</div>

<br/>

<spanclass="small">

SPAN

</span>

</div>

</body>

</html>

Selects all elements with class small and sets 5px solid red border. Notice div1 has 2 classes - small and big.

<html>

<head>

<title></title>

<scriptsrc="Scripts/jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('.small').css('border', '5px solid red');

});

</script>

</head>

<body>

<divclass="small
big">

DIV 1

</div>

<br/>

<divclass="small">

DIV 2

</div>

</body>

</html>

Selects all elements that has both the classes - small and big. There should be no space between the class names.

<scripttype="text/javascript">

$(document).ready(function () {

$('.small.big').css('border', '5px solid red');

});

</script>

If you have a space between the two class names then we are trying to find descendants, i.e. find elements with class big that are descendants of an element with class small.

<html>

<head>

<title></title>

<scriptsrc="Scripts/jquery-1.11.2.js"></script>

<scripttype="text/javascript">

$(document).ready(function () {

$('.small
.big').css('border', '5px solid red');

});

</script>

</head>

<body>

<divclass="small
big">

DIV 1

</div>

<br/>

<divclass="small">

DIV 2

<divclass="big">

DIV 3

</div>

</div>

</body>

</html>

Another way to selects all elements that has both the classes - small and big is by using filter method. But this approach is slower because it will first create a list of objects with class "small" and then removes elements that does not have class "big"