- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery before() Method
The before() method in jQuery is used to insert specified content before the selected elements.
Example
Let us now see an example to implement the before() method in jQuery −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btndemo").click(function(){ $("img").before("<strong>Text inserted before!</strong>"); }); }); </script> </head> <body> <img src="https://www.tutorialspoint.com/images/tp-logo-diamond.png" alt="Tutorialspoint Logo" width="220" height="120"><br><br> <button id="btndemo">Insert specified content</button> </body> </html>
Output
This will produce the following output −
Click on “Insert specified content” −
- Related Articles
- jQuery $.proxy() Method
- jQuery after() method
- jQuery children() method
- jQuery next() method
- jQuery nextAll() method
- jQuery attr() Method
- jQuery fadeIn() Method
- jQuery fadeTo() Method
- jQuery fadeToggle() Method
- jQuery outerHeight() Method
- jQuery outerWidth() Method
- jQuery off() Method
- jQuery slideDown() Method
- jQuery slideToggle() Method
- jQuery eq() method

Advertisements