To highlight a clicked word in the paragraph. : Paragraph « jQuery « JavaScript DHTML
- JavaScript DHTML
- jQuery
- Paragraph
To highlight a clicked word in the paragraph.
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var words = $("p:first").text().split(" ");
var text = words.join("</div> <div>");
$("p:first").html("<div>" + text + "</div>");
$("div").click(function () {
$(this).css("background-color","yellow");
});
});
</script>
</head>
<body>
<body>
<p>a b c</p>
</body>
</html>
Related examples in the same category