File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+
4+ < head >
5+ < script src ="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js "> </ script >
6+ < script >
7+ function afterText ( ) {
8+ var txt1 = `<b>I </b>` ; // Create element with HTML
9+ var txt2 = $ ( "<i></i>" ) . text ( "love " ) ; // Create with jQuery
10+ var txt3 = document . createElement ( "b" ) ; // Create with DOM
11+ txt3 . innerHTML = "jQuery!" ;
12+ $ ( "img" ) . after ( txt1 , txt2 , txt3 ) ; // Insert new elements after img
13+ }
14+
15+ function beforeText ( ) {
16+ var txt1 = `<b>I </b>` ; // Create element with HTML
17+ var txt2 = $ ( "<i></i>" ) . text ( "love " ) ; // Create with jQuery
18+ var txt3 = document . createElement ( "b" ) ; // Create with DOM
19+ txt3 . innerHTML = "jQuery!" ;
20+ $ ( "img" ) . before ( txt1 , txt2 , txt3 ) ; // Insert new elements before img
21+ }
22+ </ script >
23+ </ head >
24+
25+ < body >
26+
27+ < img src ="jqueryImg.png " alt ="jQuery " width ="100 " height ="140 ">
28+
29+ < p > Click the button to insert text after the image.</ p >
30+
31+ < button onclick ="beforeText() "> Insert before</ button >
32+ < button onclick ="afterText() "> Insert after</ button >
33+
34+ </ body >
35+
36+ </ html >
You can’t perform that action at this time.
0 commit comments