Jquery – How to get first span element of a div and change class using jQuery


I have a div with a span

<div id="div1">
    <span class="">hello</span>

When i click on div i want to change the class of only first span element of the div

$('#div1').click(function() {
    // ... check if first span element inside the div .. if there and change the class..    

Best Solution

$('#div1').click(function() {    
   $('span:first', this).prop('class', 'newClassName');