jquery - What is "+newcolor+" in CSS -
<html> <head> <title>the jquery example</title> <script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $(".inner").click(function () { var newcolor = $(this).css('background-color'); $("#destination").wrap("<div class = 'newinner' style = 'border:2px solid "+newcolor+"';></div>"); }); }); </script> <style> .inner{ margin:10px;padding:12px; border:2px solid #666; } .newinner{ padding:20px;} </style> </head> <body> <p>click on square below see result:</p> <div class = "inner" id = "destination">this test</div> <div class = "inner" style = "background-color:blue;">one</div> <div class = "inner" style = "background-color:green;">two</div> <div class = "inner" style = "background-color:red;">three</div> </body> </html>
what's +newcolor+
, copy color of clicked element, 2 +
's surrounding it?
newcolor
inside +
refers variable newcolor
described in pic below.
the +
sign use when want refer newcolor
variable newcolor
above it.
don't forget add single quote close previous code, add double quotes "
before , after plus sign , add single quote continue previous code between +newcolor+
Comments
Post a Comment