Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>jQuery innerWidth() Get & Set Example</title> <style> body { font-family: Arial, sans-serif; padding: 40px; background-color: #f9f9f9; } h1 { color: #333; } p { font-size: 16px; color: #444; } .box { position: relative; padding: 30px; background-color: #E3F2FD; border: 30px solid #1E88E5; color: #0D47A1; margin-bottom: 15px; box-sizing: content-box; width: 200px; overflow: visible; height: 120px; } .content-overlay { position: absolute; top: 30px; left: 30px; width: calc(100% - 60px); height: calc(100% - 60px); background: rgba(0, 0, 0, 0.1); pointer-events: none; } .label { position: absolute; padding: 2px 6px; font-size: 12px; color: #fff; background: #333; box-shadow: 0 1px 3px rgba(0,0,0,0.3); border-radius: 3px; white-space: nowrap; } .label.border { top: -20px; left: 30px; } .label.padding { top: 5px; left: 30px; } .label.content { top: 35px; left: 30px; } .inner-line { position: absolute; bottom: 30px; left: 0px; border-top: 2px dotted red; z-index: 1; } .inner-label { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: #C62828; color: #fff; padding: 2px 6px; font-size: 12px; border-radius: 3px; z-index: 2; white-space: nowrap; } .info-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(255,255,255,0.9); color: #333; padding: 10px 15px; font-size: 14px; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 3; text-align: center; width: fit-content; } button { margin-top: 15px; padding: 10px 20px; background-color: #1E88E5; color: white; font-size: 14px; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px; } button:hover { background-color: #1565C0; } </style> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> </head> <body> <h1>jQuery <code>innerWidth()</code> Method – Get & Set</h1> <p>Click the buttons below to get or set the <strong>innerWidth</strong> of the box. Labels mark the <em>Border</em>, <em>Padding</em>, and <em>Content</em> areas; the red dotted line shows the <code>innerWidth()</code> area (content + padding).</p> <div class="box" id="content"> <div class="label border">Border: 30px</div> <div class="label padding">Padding: 30px</div> <div class="label content">Content: 200px</div> <div class="content-overlay"></div> <div class="info-box" id="infoBox">Result will appear here.</div> </div> <button id="getInnerWidthBtn">Get innerWidth</button> <button id="setInnerWidthBtn">Set innerWidth to 300px</button> <script> $(function () { function drawInnerWidthLine() { $('.inner-line, .inner-label').remove(); const $box = $('#content'); const iw = $box.innerWidth(); const width = $box.width(); $('.label.content').text('Content: ' + width + 'px'); $box.append( $('<div class="inner-line"></div>').css({ width: iw + 'px' }), $('<div class="inner-label">innerWidth</div>') ); } drawInnerWidthLine(); $('#getInnerWidthBtn').click(function () { const iw = $('#content').innerWidth(); $('#infoBox').text('innerWidth: ' + iw + 'px'); }); $('#setInnerWidthBtn').click(function () { $('#content').innerWidth(300); drawInnerWidthLine(); $('#infoBox').text('innerWidth set to 300px'); }); }); </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