运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script> function beforeText() { var txt1 = "<b>I </b>"; // Create element with HTML var txt2 = $("<i></i>").text("love "); // Create with jQuery var txt3 = document.createElement("b"); // Create with DOM txt3.innerHTML = "jQuery!"; $("img").before(txt1, txt2, txt3); // Insert new elements before img } </script> </head> <body> <img src="/images/w3jquery.gif" alt="jQuery" width="100" height="140"> <p>Click the button to insert text before the image.</p> <button onclick="beforeText()">Insert before</button> </body> </html>