JavaScript Tutorial/jQuery/contents
Версия от 18:52, 25 мая 2010; (обсуждение)
contents() finds all the child nodes inside the matched elements
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").contents().not("[nodeType=1]").wrap("<b/>");
});
</script>
</head>
<body>
<body>
<p>Hello <a href="http://wbex.ru/">wbex</a>asdf</p>
</body>
</html>
Get tag content
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($("p").contents().text());
});
</script>
</head>
<body>
<body>
<p>Hello <span>span</span>data</p>
</body>
</html>
Wrap tag to another tag
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").contents().filter(function(){ return this.nodeType != 1; }).wrap("<b/>");
});
</script>
</head>
<body>
<body>
<p>Hello <span>span</span>data</p>
</body>
</html>