JavaScript DHTML/jQuery/prepend
Содержание
Add data to each tag with prepend
<source lang="html4strict">
<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>
<button disabled="disabled">First</button>
</body>
</html>
</source>
prepend(content): insert elements inside
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").prepend("Hello "); }); </script> <style> .selected { color:blue; } </style> </head> <body> <body>
asdf
</body>
</html>
</source>
Prepend content to the inside of every matched element
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("span").prepend("Hello ");
});
</script>
</head>
<body>
<body>
span
FOO!
</body>
</html>
</source>
Prepend query
<source lang="html4strict">
<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>
a
b</body>
</html>
</source>
Prepends a DOM Element
<source lang="html4strict">
<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
FOO!
</body>
</html>
</source>
Prepends a DOM Element to all paragraphs.
<source lang="html4strict">
<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>
asdf
</body>
</html>
</source>
Prepends some HTML to all paragraphs.
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").prepend("Hello "); }); </script> <style> .selected { color:blue; } </style> </head> <body> <body>
asdf
</body>
</html>
</source>