Thursday, 15 April 2010

css - jQuery - if text in DIV was clicked -



css - jQuery - if text in DIV was clicked -

i have divs. within these divs texts, images, tags... need show "alert", when text clicked. not images, not other tags, not text in other tags... text within divs. how jquery ?

jsfiddle example.

html

<div style="background-color:papayawhip;">some text. <img src="http://ynternet.sk/test2/close_1.jpg" /> <img src="http://ynternet.sk/test2/close_2.jpg" /> </div> <div style="background-color:moccasin;">this letters <em>and not.</em> hello again! </div> <div style="background-color:lightgoldenrodyellow;"> <img src="http://ynternet.sk/test2/close_1.jpg" /> <img src="http://ynternet.sk/test2/close_2.jpg" /> letters in new line. <img src="http://ynternet.sk/test2/close_1.jpg" /> <img src="http://ynternet.sk/test2/close_2.jpg" /> </div> <div style="background-color:wheat;">new letters in line.</div>

css

div { padding:10px 0px 0px 20px; font-family:verdana; height:40px; } em{ color:red; }

check type of source if div means text wrapped straight div. if want include mode tag em can add together in condition.

live demo

$('div').click(function(evt){ if(evt.target.tagname == 'div') alert("div clicked"); });

jquery css html select

No comments:

Post a Comment