I am trying to propagate events with jQuery using the code below:
$(document).ready(function() {
$('#main').click(function(e){
var el = e.target.nodeName;
var $jObj = $(el);//jQuery object
$jObj.css('color','green');
});
});
This is the simple html code:
<div id="main">
<p>Test one</p>
<p>Test two</p>
<p>Test three</p>
</div>
Now, If I click on one of the p elements not only the selected p changes the color to green, but all p. I cannot understand the resaon. According to the jQuery script above only the selected <p> should change the colour.
What I am doing wrong?