JavaScript Tutorial/jQuery/prepend
Содержание
Add data to each tag with prepend
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("*", document.body).each(function () {
$(this).prepend(document.createTextNode("data"));
});
});
</script>
<style>
.y { background:yellow; }
</style>
</head>
<body>
<body>
<div><button disabled="disabled">First</button> <span class="selected"></span>
<span></span>
</div>
</body>
</html>
prepend(content): insert elements inside
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").prepend("<b>Hello </b>");
});
</script>
<style>
.selected { color:blue; }
</style>
</head>
<body>
<body>
<p>asdf</p>
</body>
</html>
Prepend content to the inside of every matched element
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("span").prepend("<b>Hello </b>");
});
</script>
</head>
<body>
<body>
<span>span</span>
<div id="foo">FOO!</div>
</body>
</html>
Prepend query
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").prepend( $("b") );
});
</script>
</head>
<body>
<body>
<p> a</p><b>b</b>
</body>
</html>
Prepends a DOM Element
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("span").prepend(document.createTextNode("Hello "));
});
</script>
</head>
<body>
<body>
<span>span</span>
<div id="foo">FOO!</div>
</body>
</html>
Prepends a DOM Element to all paragraphs.
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").prepend(document.createTextNode("Hello "));
});
</script>
</head>
<body>
<body>
<p>asdf</p>
</body>
</html>
Prepends some HTML to all paragraphs.
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").prepend("<b>Hello </b>");
});
</script>
<style>
.selected { color:blue; }
</style>
</head>
<body>
<body>
<p>asdf</p>
</body>
</html>