Initializing...
Liveweave
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
build
Tools
expand_more
restart_alt
Load base template
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!DOCTYPE html> <html> <head> <title>If values are the same update code</title> <meta charset='utf-8'> <meta name='viewport' content='initial-scale=1.0'> <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.min.js'></script> </head> <body> <table align="center"> <tr> <td> </td> <td> <input type='number' min="0" class="padding-top" value="10"> </td> <td> </td> </tr> <tr> <td> <input type='number' min="0" class="padding-left" value="0"> </td> <td> <input type='text' class="padding-final"> </td> <td> <input type='number' min="0" class="padding-right" value="0"> </td> </tr> <tr> <td> </td> <td> <input type='number' min="0" class="padding-bottom" value="10"> </td> <td> </td> </tr> </table> </body> </html>
input[type=text], input[type=number] { margin: .5em 0; width: 90%; }
$(document).ready(function() { var top = $(".padding-top").val(), bottom = $(".padding-bottom").val(), left = $(".padding-left").val(), right = $(".padding-right").val(), result = $(".padding-final"); // Update padding code var Finalize = function() { if ((top === "") && (right === "") && (bottom === "") && (left === "")) { // Check if all are empty result.val(""); } else if ((top === right) && (bottom === left)) { // If all are same result.val("padding: " + top + "px;"); } else if ((top === bottom) && (left === right)) { // Check if first two values are same result.val("padding: " + top + "px " + left + "px;"); } else { result.val("padding: " + top + "px " + right + "px " + bottom + "px " + left + "px;"); } }; // Update padding code when sides change $(window).on('load keyup change', function() { Finalize(); }); });