Code:
<! DOCTYPE HTML > < HTML > < head > < Meta charset = "UTF-. 8" > < title > Document _ replacement operation </ title > < Script type = "text / JavaScript" the src = "JS / jQuery-1.11 .0.min.js " > </ Script > < Script > $ ( function () { // replace the contents B out of the content a at $ ( " P " ) .replaceWith ( "<strong> your least favorite fruit? </ strong>" ); // Another way to achieve: $ ("? ".) ReplaceAll (" <strong> your least favorite fruit </ strong> the p-"); }); </ Script > </ head > < body > < the p- title = "choose your favorite fruit." > your favorite fruit? </ the p- > < ul > < li title = 'apple' > Apple </ li > < li title = 'orange ' > orange </ Li > < Li title = 'Pineapple'>菠萝</li> </ul> </body> </html>
Can be seen through the code, run-time should display your favorite fruit? But time is running really find your least favorite fruit is bold, and there is a way to achieve, $ ( "<strong> your least favorite fruit? </ Strong>"). ReplaceAll ( " p ") ;, with <strong> <strong /> instead of the middle of the content inside the content p, and $ ( " p " ) .replaceWith ( " <strong> your least favorite fruit? </ strong> " ); by obtaining the content of "p", and then replaced by the contents of the method body, you can achieve the same effect.