We would like to know how to split text by space.
<html>
<head>
<script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w ww. jav a2s . c om-->
var newText = $("p").text().split(" ").join("</div> <div>");
$("p").html(newText);
});
</script>
<style>
.y { background:yellow; }
</style>
</head>
<body>
<body>
<p>a ab abc</p>
</body>
</html>
The code above is rendered as follows: