Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery Get Attribute 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: 30px; background: #f9f9f9; } h2 { color: #222; } a, img { display: block; margin-top: 20px; } button { margin-top: 20px; padding: 10px 20px; background: #3490dc; color: white; border: none; border-radius: 4px; cursor: pointer; } .info { margin-top: 20px; font-weight: bold; color: #2d3748; } </style> </head> <body> <h2>Get Attributes with jQuery <code>.attr()</code></h2> <p>This example demonstrates how to get the value of the <code>href</code> and <code>src</code> attributes using jQuery.</p> <a id="myLink" href="https://example.com" target="_blank">Visit Example Site</a> <img id="myImage" src="https://picsum.photos/200/100" alt="Random Image" width="200"> <button id="getAttrBtn">Get Attributes</button> <div class="info" id="linkInfo"></div> <div class="info" id="imgInfo"></div> <script> $(document).ready(function(){ $('#getAttrBtn').click(function(){ var linkHref = $('#myLink').attr('href'); var imageSrc = $('#myImage').attr('src'); $('#linkInfo').text("Link Href: " + linkHref); $('#imgInfo').text("Image Src: " + imageSrc); }); }); </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