Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery before() Method Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <style> body { font-family: Arial, sans-serif; padding: 40px; background: #f4f4f4; } .content { max-width: 600px; margin: auto; background: #fff; padding: 30px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .footer { margin-top: 10px; font-size: 14px; color: #fff; background: #007bff; border-top: 5px solid #333; padding: 30px; text-align: center; } .notice { background: #d4edda; color: #155724; padding: 10px 15px; border: 1px solid #c3e6cb; margin-bottom: 20px; text-align: center; } input[type="email"] { padding: 10px; width: 70%; border: 1px solid #ccc; border-radius: 4px; margin-right: 10px; } button { padding: 10px 20px; background: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; } </style> </head> <body> <h2>jQuery Add – before() Method</h2> <p>The <kbd>before()</kbd> method inserts content right before each element in the matched set, useful for UI messages and alerts.</p> <div class="content"> <input type="email" id="email" placeholder="Enter your email"> <button id="subscribeBtn">Subscribe</button> <div class="footer"> © 2025 ReadSpecs. All rights reserved. </div> </div> <script> $(document).ready(function(){ $("#subscribeBtn").click(function(){ const email = $("#email").val().trim(); if (email) { $("#email").before('<div class="notice">You are subscribed with: <strong>' + email + '</strong></div>'); $(this).prop("disabled", true).text("Subscribed"); $("#email").prop("disabled", true); } }); }); </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console