{"id":16856,"date":"2016-07-13T23:20:26","date_gmt":"2016-07-13T23:20:26","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=16856"},"modified":"2016-07-13T23:20:26","modified_gmt":"2016-07-13T23:20:26","slug":"web-design-jquery-css-and-javascript-style-boundary-testing","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/web-design-jquery-css-and-javascript-style-boundary-testing\/","title":{"rendered":"Web design:  jQuery css() and JavaScript style:  boundary testing"},"content":{"rendered":"<h1>The tutor discusses what he noticed while experimenting with jQuery css() and JavaScript style.<\/h1>\n<p>JavaScript has a style function that allows you to access style attributes of an element.  For example, to get an element&#8217;s color:<\/p>\n<p style=\"font-family:monospace\">\nvar e1_color=document.getElementById(&#8220;e1&#8221;).style.color;\n<\/p>\n<p>However, as I understand, you&#8217;re not meant to harvest the entire style at once:<\/p>\n<p style=\"font-family:monospace\">\nvar e1_style=document.getElementById(&#8220;e1&#8221;).style;    \/\/<span style=\"color:red\">not intended<\/span><\/p>\n<p>Furthermore, let&#8217;s imagine you do so anyway, then try to convey that style to another element:<\/p>\n<p style=\"font-family:monospace\">\nvar e1_style=document.getElementById(&#8220;e1&#8221;).style;<br \/>\ndocument.getElementById(&#8220;e2&#8221;).style=e1_style;<br \/>\n\/\/<span style=\"color:red\">won&#8217;t work, according to my tests<\/span>\n<\/p>\n<p>Curiously, though, I&#8217;ve found that<\/p>\n<p style=\"font-family:monospace\">\nvar e1_style=document.getElementById(&#8220;e1&#8221;).style;<br \/>\njQuery(&#8220;#e2&#8221;).css(e1_style);<\/p>\n<p>does work on Chrome and Firefox (but not ie11).<\/p>\n<p>It&#8217;s not a recommended way to change the style of an element, but it hints at how JavaScript and jQuery can have deeper communication than JavaScript with itself.  It also reminds of the potential differences from browser to browser.<\/p>\n<p>I&#8217;ll be talking more about JavaScript and jQuery in future posts:)<\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/www.w3schools.com\/jsref\/dom_obj_style.asp\">w3schools<\/a><\/p>\n<p>Pollock, John.  <u>jQuery:  A Beginner&#8217;s Guide<\/u>.  Toronto:  McGraw-Hill, 2014.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor discusses what he noticed while experimenting with jQuery css() and JavaScript style. JavaScript has &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/web-design-jquery-css-and-javascript-style-boundary-testing\/\"> <span class=\"screen-reader-text\">Web design:  jQuery css() and JavaScript style:  boundary testing<\/span> Read more \u2192<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1714,105,1631,1663,1713,1691,1662,837],"tags":[],"class_list":["post-16856","post","type-post","status-publish","format-standard","hentry","category-chrome","category-computer-science","category-css","category-firefox","category-javascript","category-jquery","category-web-browsers","category-web-design"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/16856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=16856"}],"version-history":[{"count":23,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/16856\/revisions"}],"predecessor-version":[{"id":16879,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/16856\/revisions\/16879"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=16856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=16856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=16856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}