SlideShare a Scribd company logo
Presentational jQuery
                        Balancing jQuery and CSS




Presentational jQuery                              Doug Neiner
Presentational jQuery   Doug Neiner
Presentational jQuery   Doug Neiner
Presentational jQuery
                        Balancing jQuery and CSS




Presentational jQuery                              Doug Neiner
Presentational jQuery
 • jQuery          CSS Primer

 • .css()       vs. Style Sheets vs. <style> blocks

 • Rules         of the Road
                        Balancing jQuery and CSS

 • Moving               Around




Presentational jQuery                                 Doug Neiner
jQuery CSS Primer
 • jQuery adjusts the .style property on the DOM
    element to make CSS changes
    div.style.backgroundColor = "#aaa";




Presentational jQuery                              Doug Neiner
jQuery CSS Primer
   var div = document.getElementById( "#test" );

   // JS
   div.style.backgroundColor = "#aaa";

   // jQuery
   $(div).css( "backgroundColor", "#aaa" );
   $(div).css( "background-color", "#aaa" );

   // JS
   div.style.color = "#000";
   div.style.textDecoration = "underline";

   // jQuery
   $(div).css({
     color: "#000",
     textDecoration: "underline"
   });


Presentational jQuery                              Doug Neiner
jQuery CSS Primer
 • jQuery adjusts the            .style   property on the DOM
    element
    div.style.backgroundColor = "#aaa";


 • It   is the equivalent of setting an inline style
    <div style="background-color: #aaa"> … </div>


 • This  overrides pretty much any rule specified
    elsewhere




Presentational jQuery                                           Doug Neiner
Getting CSS Values
   // Get the value for #test
   $( "#test" ).css( "border-top-width" );

   // Get the value for the first item in the result set
   $( "div" ).css( "border-top-width" );

   // Get all the values in the result set
   var values = $( "div" ).map( function () {
     return $(this).css( "border-top-width" );
   }).get();




Presentational jQuery                                     Doug Neiner
Dynamic Setters
   // Get the value for #test
   $( "div" ).css( "border-top-width", function ( i, old ) {
      return ( i + 1 ) * 2; // New Value
   });




Presentational jQuery                                          Doug Neiner
.css() vs. Style Sheets vs.
                         <style>
                    Choosing the Best Tool for the Task




Presentational jQuery                                     Doug Neiner
Style Sheet
 • Pros
     •   Very fast
     •   Can be easily overridden
     •   Provides a customized foundation
     •   Clear separation of logic and style

 • Cons
     •   You must know the element states before hand
     •   You must be able to select the elements
     •   Is not (generally) reactive

Presentational jQuery                                   Doug Neiner
<style> Block
 • Pros
     •   Very fast
     •   Can be overridden
     •   Adds to a foundation, or provides its own
     •   Can be reactive

 • Cons
     •   Less separation of logic and style
     •   You must be able to select the elements



Presentational jQuery                                Doug Neiner
.css() Method
 • Pros
     •   Very convenient
     •   Highly dynamic and reactive
     •   Can act on an arbitrary selection of elements

 • Cons
     •   Not easily overridden
     •   No separation of logic and style




Presentational jQuery                                    Doug Neiner
Style Sheet                 <style>                jQuery
 • To  set initial      • BulkChanges       • Totransition
    state                to elements         between
                                             states
 • To  handle           • Defaults   that
    predictable          can be             • Tohandle
    states               overridden          unpredictable
                                             states
 • Bulk  changes
    to elements                             • One and two-
                                             off changes
                                             to elements


Presentational jQuery                                 Doug Neiner
A note to plugin developers
 • If    you need a lot of styles, do it in a stylesheet
     •   No asset path issues
     •   Easily customized
     •   Nice separation of logic and style

 • Ifyou have to do it only in JS, prepend it to the
    <head> in a <style> block.




Presentational jQuery                                  Doug Neiner
Rules of the Road
                        Avoiding Common Mistakes




Presentational jQuery                              Doug Neiner
Beware of Iteration
           Don't call .css() multiple times unless needed




Presentational jQuery                                   Doug Neiner
Incorrect Approach
   var $div = $("div");

   $div.css('backgroundColor', 'red');

   if ( some_test === true ) {
     $div.css('color', 'black');
   }

   ...

   if ( some_other_test === true ) {
     $div.css('display', 'block')
         .css('position', 'relative');
   }




Presentational jQuery                    Doug Neiner
Correct Approach
   var css = {
     backgroundColor: "red"
   };

   if ( some_test === true ) {
     css.color = "black";
   }

   ...

   if ( some_other_test === true ) {
     css.display = "block";
     css.position = "relative";
   }

   $("div").css( css );




Presentational jQuery                  Doug Neiner
Incorrect Approach
   var colors = $(".color");

   $(".filter-by-color").click( function () {
      colors.toggle();
   });




Presentational jQuery                          Doug Neiner
Correct Approach
   var color_parent = $("#list");

   $(".filter-by-color").click( function () {
      color_parent.toggleClass( "show-colors" );
   });



   .color { display: none }

   #list.show-colors .color { display: block }




Presentational jQuery                              Doug Neiner
Class Methods
 • addClass(            classNames )

 • removeClass(            classNames )

 • toggleClass(           classNames, is_true )

 • hasClass(            className )

 • is(    ".className1.className2")




Presentational jQuery                             Doug Neiner
Write code like you
                            run errands
                    Don't keep revisiting the same store
                             on the same day




Presentational jQuery                                      Doug Neiner
Setting Initial State
                             To js or no-js




Presentational jQuery                           Doug Neiner
Incorrect Approach

   $( document ).ready( function () {
      $( "#dialog, #menu, #footer" ).hide();
      $( "#progress-bar" ).show();
   });




Presentational jQuery                          Doug Neiner
Correct Approach
   <html class="no-js">
   …
   <script>
   document.documentElement.className =
     document.documentElement.className.replace("no-js", "js");
   </script>


   #dialog, #menu, #footer { display: block }

   .no-js #progress-bar,
   .js #dialog, .js #menu, .js #footer { display: none }




                          Modernizer does this for you


Presentational jQuery                                             Doug Neiner
Moving Around
                          jQuery Animation

                                                                   . I will
                                                         ex ercise
                                                   e coding
                                           s a liv                rial on
                                     on wa           e
                         Thi s secti               b        e mate g, and
                                                     ng som queuin
                                             blishi thod,
                                       on pu n me
                            w orking nimatio
                                    's A             sing.
                           jQuery                ea


Presentational jQuery                                              Doug Neiner
twitter   @dougneiner

                         email    doug@dougneiner.com

                          web     http://dougneiner.com




Presentational jQuery                                     Doug Neiner

More Related Content

What's hot (19)

JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
BorisMoore
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
jeresig
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
jeresig
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
J query
J queryJ query
J query
David Giard
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
jeresig
 
DirectToWeb 2.0
DirectToWeb 2.0DirectToWeb 2.0
DirectToWeb 2.0
WO Community
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit
Girish Venkatachalam
 
JQuery
JQueryJQuery
JQuery
baabtra.com - No. 1 supplier of quality freshers
 
J query presentation
J query presentationJ query presentation
J query presentation
akanksha17
 
State of jQuery and Drupal
State of jQuery and DrupalState of jQuery and Drupal
State of jQuery and Drupal
jeresig
 
New text documentfsdfs
New text documentfsdfsNew text documentfsdfs
New text documentfsdfs
Ah Lom
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
Ralph Whitbeck
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
jeresig
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
Diogo Antunes
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
jeresig
 
jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014
dmethvin
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
BorisMoore
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
jeresig
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
jeresig
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
jeresig
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit
Girish Venkatachalam
 
J query presentation
J query presentationJ query presentation
J query presentation
akanksha17
 
State of jQuery and Drupal
State of jQuery and DrupalState of jQuery and Drupal
State of jQuery and Drupal
jeresig
 
New text documentfsdfs
New text documentfsdfsNew text documentfsdfs
New text documentfsdfs
Ah Lom
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
Ralph Whitbeck
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
jeresig
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
jeresig
 
jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014
dmethvin
 

Viewers also liked (8)

Introducing Amplify
Introducing AmplifyIntroducing Amplify
Introducing Amplify
appendTo
 
HTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use TodayHTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use Today
Todd Anglin
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
Nicole Sullivan
 
Fundamentals of Web for Non-Developers
Fundamentals of Web for Non-DevelopersFundamentals of Web for Non-Developers
Fundamentals of Web for Non-Developers
Lemi Orhan Ergin
 
Basic Web Concepts
Basic Web ConceptsBasic Web Concepts
Basic Web Concepts
Cherry Ann Labandero
 
Ppt of web development
Ppt of web developmentPpt of web development
Ppt of web development
bethanygfair
 
Fundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersFundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-Developers
Lemi Orhan Ergin
 
CSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI DevelopersCSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI Developers
Darren Gideon
 
Introducing Amplify
Introducing AmplifyIntroducing Amplify
Introducing Amplify
appendTo
 
HTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use TodayHTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use Today
Todd Anglin
 
Fundamentals of Web for Non-Developers
Fundamentals of Web for Non-DevelopersFundamentals of Web for Non-Developers
Fundamentals of Web for Non-Developers
Lemi Orhan Ergin
 
Ppt of web development
Ppt of web developmentPpt of web development
Ppt of web development
bethanygfair
 
Fundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersFundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-Developers
Lemi Orhan Ergin
 
CSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI DevelopersCSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI Developers
Darren Gideon
 

Similar to Presentational jQuery (20)

Jquery
JqueryJquery
Jquery
Zoya Shaikh
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
Doug Neiner
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
Amir Barylko
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
UC Berkeley Graduate School of Journalism
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3
luckysb16
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Siva Arunachalam
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
Intro to jQuery for Drupal
Intro to jQuery for DrupalIntro to jQuery for Drupal
Intro to jQuery for Drupal
jhamiltoorion
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
MongoSF
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
Fitz Agard
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
Remy Sharp
 
Tips for writing Javascript for Drupal
Tips for writing Javascript for DrupalTips for writing Javascript for Drupal
Tips for writing Javascript for Drupal
Sergey Semashko
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
Jquery
JqueryJquery
Jquery
baabtra.com - No. 1 supplier of quality freshers
 
Inside jQuery (2011)
Inside jQuery (2011)Inside jQuery (2011)
Inside jQuery (2011)
Kenneth Auchenberg
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
Rebecca Murphey
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
Doug Neiner
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
Amir Barylko
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3
luckysb16
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
Intro to jQuery for Drupal
Intro to jQuery for DrupalIntro to jQuery for Drupal
Intro to jQuery for Drupal
jhamiltoorion
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
MongoSF
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
Fitz Agard
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
Remy Sharp
 
Tips for writing Javascript for Drupal
Tips for writing Javascript for DrupalTips for writing Javascript for Drupal
Tips for writing Javascript for Drupal
Sergey Semashko
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 

Recently uploaded (20)

launch your uber clone app in a weeks.pdf
launch your uber clone app in a weeks.pdflaunch your uber clone app in a weeks.pdf
launch your uber clone app in a weeks.pdf
V3cube
 
ISTQB Foundation Level – Chapter 4: Test Design Techniques
ISTQB Foundation Level – Chapter 4: Test Design TechniquesISTQB Foundation Level – Chapter 4: Test Design Techniques
ISTQB Foundation Level – Chapter 4: Test Design Techniques
zubair khan
 
CLI, HTTP, GenAI and MCP telemetry/observability in Java
CLI, HTTP, GenAI and MCP telemetry/observability in JavaCLI, HTTP, GenAI and MCP telemetry/observability in Java
CLI, HTTP, GenAI and MCP telemetry/observability in Java
Pavel Vlasov
 
Autopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
Autopilot for Everyone Series - Session 3: Exploring Real-World Use CasesAutopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
Autopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
UiPathCommunity
 
oil seed milling- extraction and Refining
oil seed milling- extraction and Refiningoil seed milling- extraction and Refining
oil seed milling- extraction and Refining
MaheshKadam154653
 
Meme Coin Development The Roadmap from Concept to Triumph.pdf
Meme Coin Development The Roadmap from Concept to Triumph.pdfMeme Coin Development The Roadmap from Concept to Triumph.pdf
Meme Coin Development The Roadmap from Concept to Triumph.pdf
Abi john
 
Monitor Kafka Clients Centrally with KIP-714
Monitor Kafka Clients Centrally with KIP-714Monitor Kafka Clients Centrally with KIP-714
Monitor Kafka Clients Centrally with KIP-714
Kumar Keshav
 
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Javier García Molleja
 
Jade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay’s Perspective on AI and Supercomputing Growth in DallasJade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay
 
Implementing Function Calling LLMs without Fear.pdf
Implementing Function Calling LLMs without Fear.pdfImplementing Function Calling LLMs without Fear.pdf
Implementing Function Calling LLMs without Fear.pdf
Benjamin Bengfort
 
Teach the importance of logic (programming)in Computer Science and why it is ...
Teach the importance of logic (programming)in Computer Science and why it is ...Teach the importance of logic (programming)in Computer Science and why it is ...
Teach the importance of logic (programming)in Computer Science and why it is ...
Universidad Rey Juan Carlos
 
Towards value-awareness in administrative processes: an approach based on con...
Towards value-awareness in administrative processes: an approach based on con...Towards value-awareness in administrative processes: an approach based on con...
Towards value-awareness in administrative processes: an approach based on con...
Universidad Rey Juan Carlos
 
What comes after world domination with Daniel Stenberg, April 2025
What comes after world domination with Daniel Stenberg, April 2025What comes after world domination with Daniel Stenberg, April 2025
What comes after world domination with Daniel Stenberg, April 2025
Daniel Stenberg
 
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 ReleaseBay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
carlyakerly1
 
Introduction to LLM Post-Training - MIT 6.S191 2025
Introduction to LLM Post-Training - MIT 6.S191 2025Introduction to LLM Post-Training - MIT 6.S191 2025
Introduction to LLM Post-Training - MIT 6.S191 2025
Maxime Labonne
 
Managing Multiple Logical Volumes - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdfManaging Multiple Logical Volumes - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdf
RHCSA Guru
 
Transcript: On the rise: Book subjects on the move in the Canadian market - T...
Transcript: On the rise: Book subjects on the move in the Canadian market - T...Transcript: On the rise: Book subjects on the move in the Canadian market - T...
Transcript: On the rise: Book subjects on the move in the Canadian market - T...
BookNet Canada
 
The Five Pillars of AI Readiness Webinar
The Five Pillars of AI Readiness WebinarThe Five Pillars of AI Readiness Webinar
The Five Pillars of AI Readiness Webinar
BrainSell Technologies
 
Driving Transportation Forward: Real-World Data Solutions
Driving Transportation Forward: Real-World Data SolutionsDriving Transportation Forward: Real-World Data Solutions
Driving Transportation Forward: Real-World Data Solutions
Safe Software
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
BrainSell Technologies
 
launch your uber clone app in a weeks.pdf
launch your uber clone app in a weeks.pdflaunch your uber clone app in a weeks.pdf
launch your uber clone app in a weeks.pdf
V3cube
 
ISTQB Foundation Level – Chapter 4: Test Design Techniques
ISTQB Foundation Level – Chapter 4: Test Design TechniquesISTQB Foundation Level – Chapter 4: Test Design Techniques
ISTQB Foundation Level – Chapter 4: Test Design Techniques
zubair khan
 
CLI, HTTP, GenAI and MCP telemetry/observability in Java
CLI, HTTP, GenAI and MCP telemetry/observability in JavaCLI, HTTP, GenAI and MCP telemetry/observability in Java
CLI, HTTP, GenAI and MCP telemetry/observability in Java
Pavel Vlasov
 
Autopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
Autopilot for Everyone Series - Session 3: Exploring Real-World Use CasesAutopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
Autopilot for Everyone Series - Session 3: Exploring Real-World Use Cases
UiPathCommunity
 
oil seed milling- extraction and Refining
oil seed milling- extraction and Refiningoil seed milling- extraction and Refining
oil seed milling- extraction and Refining
MaheshKadam154653
 
Meme Coin Development The Roadmap from Concept to Triumph.pdf
Meme Coin Development The Roadmap from Concept to Triumph.pdfMeme Coin Development The Roadmap from Concept to Triumph.pdf
Meme Coin Development The Roadmap from Concept to Triumph.pdf
Abi john
 
Monitor Kafka Clients Centrally with KIP-714
Monitor Kafka Clients Centrally with KIP-714Monitor Kafka Clients Centrally with KIP-714
Monitor Kafka Clients Centrally with KIP-714
Kumar Keshav
 
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Low-velocity penetration impact behavior of Triply Periodic Minimal Surface s...
Javier García Molleja
 
Jade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay’s Perspective on AI and Supercomputing Growth in DallasJade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay’s Perspective on AI and Supercomputing Growth in Dallas
Jade Malay
 
Implementing Function Calling LLMs without Fear.pdf
Implementing Function Calling LLMs without Fear.pdfImplementing Function Calling LLMs without Fear.pdf
Implementing Function Calling LLMs without Fear.pdf
Benjamin Bengfort
 
Teach the importance of logic (programming)in Computer Science and why it is ...
Teach the importance of logic (programming)in Computer Science and why it is ...Teach the importance of logic (programming)in Computer Science and why it is ...
Teach the importance of logic (programming)in Computer Science and why it is ...
Universidad Rey Juan Carlos
 
Towards value-awareness in administrative processes: an approach based on con...
Towards value-awareness in administrative processes: an approach based on con...Towards value-awareness in administrative processes: an approach based on con...
Towards value-awareness in administrative processes: an approach based on con...
Universidad Rey Juan Carlos
 
What comes after world domination with Daniel Stenberg, April 2025
What comes after world domination with Daniel Stenberg, April 2025What comes after world domination with Daniel Stenberg, April 2025
What comes after world domination with Daniel Stenberg, April 2025
Daniel Stenberg
 
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 ReleaseBay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
Bay Area Apache Spark ™ Meetup: Upcoming Apache Spark 4.0.0 Release
carlyakerly1
 
Introduction to LLM Post-Training - MIT 6.S191 2025
Introduction to LLM Post-Training - MIT 6.S191 2025Introduction to LLM Post-Training - MIT 6.S191 2025
Introduction to LLM Post-Training - MIT 6.S191 2025
Maxime Labonne
 
Managing Multiple Logical Volumes - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdfManaging Multiple Logical Volumes - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdf
RHCSA Guru
 
Transcript: On the rise: Book subjects on the move in the Canadian market - T...
Transcript: On the rise: Book subjects on the move in the Canadian market - T...Transcript: On the rise: Book subjects on the move in the Canadian market - T...
Transcript: On the rise: Book subjects on the move in the Canadian market - T...
BookNet Canada
 
The Five Pillars of AI Readiness Webinar
The Five Pillars of AI Readiness WebinarThe Five Pillars of AI Readiness Webinar
The Five Pillars of AI Readiness Webinar
BrainSell Technologies
 
Driving Transportation Forward: Real-World Data Solutions
Driving Transportation Forward: Real-World Data SolutionsDriving Transportation Forward: Real-World Data Solutions
Driving Transportation Forward: Real-World Data Solutions
Safe Software
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
BrainSell Technologies
 

Presentational jQuery

  • 1. Presentational jQuery Balancing jQuery and CSS Presentational jQuery Doug Neiner
  • 2. Presentational jQuery Doug Neiner
  • 3. Presentational jQuery Doug Neiner
  • 4. Presentational jQuery Balancing jQuery and CSS Presentational jQuery Doug Neiner
  • 5. Presentational jQuery • jQuery CSS Primer • .css() vs. Style Sheets vs. <style> blocks • Rules of the Road Balancing jQuery and CSS • Moving Around Presentational jQuery Doug Neiner
  • 6. jQuery CSS Primer • jQuery adjusts the .style property on the DOM element to make CSS changes div.style.backgroundColor = "#aaa"; Presentational jQuery Doug Neiner
  • 7. jQuery CSS Primer var div = document.getElementById( "#test" ); // JS div.style.backgroundColor = "#aaa"; // jQuery $(div).css( "backgroundColor", "#aaa" ); $(div).css( "background-color", "#aaa" ); // JS div.style.color = "#000"; div.style.textDecoration = "underline"; // jQuery $(div).css({ color: "#000", textDecoration: "underline" }); Presentational jQuery Doug Neiner
  • 8. jQuery CSS Primer • jQuery adjusts the .style property on the DOM element div.style.backgroundColor = "#aaa"; • It is the equivalent of setting an inline style <div style="background-color: #aaa"> … </div> • This overrides pretty much any rule specified elsewhere Presentational jQuery Doug Neiner
  • 9. Getting CSS Values // Get the value for #test $( "#test" ).css( "border-top-width" ); // Get the value for the first item in the result set $( "div" ).css( "border-top-width" ); // Get all the values in the result set var values = $( "div" ).map( function () { return $(this).css( "border-top-width" ); }).get(); Presentational jQuery Doug Neiner
  • 10. Dynamic Setters // Get the value for #test $( "div" ).css( "border-top-width", function ( i, old ) { return ( i + 1 ) * 2; // New Value }); Presentational jQuery Doug Neiner
  • 11. .css() vs. Style Sheets vs. <style> Choosing the Best Tool for the Task Presentational jQuery Doug Neiner
  • 12. Style Sheet • Pros • Very fast • Can be easily overridden • Provides a customized foundation • Clear separation of logic and style • Cons • You must know the element states before hand • You must be able to select the elements • Is not (generally) reactive Presentational jQuery Doug Neiner
  • 13. <style> Block • Pros • Very fast • Can be overridden • Adds to a foundation, or provides its own • Can be reactive • Cons • Less separation of logic and style • You must be able to select the elements Presentational jQuery Doug Neiner
  • 14. .css() Method • Pros • Very convenient • Highly dynamic and reactive • Can act on an arbitrary selection of elements • Cons • Not easily overridden • No separation of logic and style Presentational jQuery Doug Neiner
  • 15. Style Sheet <style> jQuery • To set initial • BulkChanges • Totransition state to elements between states • To handle • Defaults that predictable can be • Tohandle states overridden unpredictable states • Bulk changes to elements • One and two- off changes to elements Presentational jQuery Doug Neiner
  • 16. A note to plugin developers • If you need a lot of styles, do it in a stylesheet • No asset path issues • Easily customized • Nice separation of logic and style • Ifyou have to do it only in JS, prepend it to the <head> in a <style> block. Presentational jQuery Doug Neiner
  • 17. Rules of the Road Avoiding Common Mistakes Presentational jQuery Doug Neiner
  • 18. Beware of Iteration Don't call .css() multiple times unless needed Presentational jQuery Doug Neiner
  • 19. Incorrect Approach var $div = $("div"); $div.css('backgroundColor', 'red'); if ( some_test === true ) { $div.css('color', 'black'); } ... if ( some_other_test === true ) { $div.css('display', 'block') .css('position', 'relative'); } Presentational jQuery Doug Neiner
  • 20. Correct Approach var css = { backgroundColor: "red" }; if ( some_test === true ) { css.color = "black"; } ... if ( some_other_test === true ) { css.display = "block"; css.position = "relative"; } $("div").css( css ); Presentational jQuery Doug Neiner
  • 21. Incorrect Approach var colors = $(".color"); $(".filter-by-color").click( function () { colors.toggle(); }); Presentational jQuery Doug Neiner
  • 22. Correct Approach var color_parent = $("#list"); $(".filter-by-color").click( function () { color_parent.toggleClass( "show-colors" ); }); .color { display: none } #list.show-colors .color { display: block } Presentational jQuery Doug Neiner
  • 23. Class Methods • addClass( classNames ) • removeClass( classNames ) • toggleClass( classNames, is_true ) • hasClass( className ) • is( ".className1.className2") Presentational jQuery Doug Neiner
  • 24. Write code like you run errands Don't keep revisiting the same store on the same day Presentational jQuery Doug Neiner
  • 25. Setting Initial State To js or no-js Presentational jQuery Doug Neiner
  • 26. Incorrect Approach $( document ).ready( function () { $( "#dialog, #menu, #footer" ).hide(); $( "#progress-bar" ).show(); }); Presentational jQuery Doug Neiner
  • 27. Correct Approach <html class="no-js"> … <script> document.documentElement.className = document.documentElement.className.replace("no-js", "js"); </script> #dialog, #menu, #footer { display: block } .no-js #progress-bar, .js #dialog, .js #menu, .js #footer { display: none } Modernizer does this for you Presentational jQuery Doug Neiner
  • 28. Moving Around jQuery Animation . I will ex ercise e coding s a liv rial on on wa e Thi s secti b e mate g, and ng som queuin blishi thod, on pu n me w orking nimatio 's A sing. jQuery ea Presentational jQuery Doug Neiner
  • 29. twitter @dougneiner email [email protected] web http://dougneiner.com Presentational jQuery Doug Neiner

Editor's Notes