JavaScript DHTML/jQuery/before
Содержание
- 1 Add before and after
- 2 Add tag before
- 3 Add text node before
- 4 before(content): Insert content before each of the matched elements.
- 5 Inserts a DOM element before all paragraphs.
- 6 Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
- 7 Inserts some HTML before all paragraphs.
Add before and after
<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") .before("
Quotes
") .after("
\n" + " - after\n" + "
\n"); }
);
</script> <style type="text/css">
p {
margin: 5px;
} p.tmpAttribution {
text-align: right;
}
</style> </head> <body>
asdf
</body>
</html>
</source>
Add tag before
<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").before("Hello");
}); </script> </head> <body> <body> b
p
</body>
</html>
</source>
Add text node before
<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").before( document.createTextNode("Hello") ); }); </script> </head> <body> <body> b
p
</body>
</html>
</source>
before(content): Insert content before each of the matched elements.
<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").before( $("b") ); }); </script> </head> <body> <body> asdf
asdf:
</body>
</html>
</source>
Inserts a DOM element before 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").before( document.createTextNode("Hello") ); }); </script> </head> <body> <body> asdf
asdf:
</body>
</html>
</source>
Inserts a jQuery object (similar to an Array of DOM Elements) before 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").before( $("b") ); }); </script> </head> <body> <body> asdf
asdf:
</body>
</html>
</source>
Inserts some HTML before 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").before("Hello"); }); </script> </head> <body> <body> asdf
asdf:
</body>
</html>
</source>