SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
#2




                    Day #1

     Creating the Wrapped Element Set

                  Wildan Maulana
           wildan.m@openthinklabs.com



         http://workshop.openthinklabs.com
This Presentation Cover
●   Selecting elements to be wrapped by jQuery
    using selectors
●   Creating and placing new HTML elements in
    the DOM
●   Manipulating the wrapped element set
Selecting elements for manipulation
●   Selectors Lab
Using basic CSS selectors
●   Selection by an element's ID, CSS class name, tag name, and the DOM
    hierarchy of the page elements
    ●    a → this selector matches all link (<a>) elements
    ●    #specialD → This selector matches element that have an id of specialID
    ●    .specialClass → This selector matches elements that have the class of
         specialClass
    ●    a#specialID .specialClass → this selector matches links with     an id of
         specialID and a class of specialClass
    ●    p a.specialClass → This selector matches link with a class of
         specialClass declared within <p> elements
        Use Selector labs for exercise using
        various basic CSS selectors ...               $("p a.specialClass")
Using child, container, and attribute selectors

<ul class="myList">                                    If we want to select the link to
 <li><a href="http://jquery.com">jQuery supports</a>
  <ul>                                                 the remote jQuery site basic
    <li><a href="css1">CSS1</a></li>                   css selector ul.myList li a will
    <li><a href="css2">CSS2</a></li>                   not work ..
    <li><a href="css3">CSS3</a></li>
    <li>Basic XPath</li>
  </ul>
 </li>                                                 The right approach is using
 <li>jQuery also supports                              child selectors :
  <ul>
    <li>Custom selectors</li>
    <li>Form selectors</li>
  </ul>
 </li>                                                   ul.myList > li > a
</ul>
Attribute Selectors
●   To select a link that points to an external site we
    can use :
                          <li><a href="http://jquery.com">jQuery supports</a>
                             <ul>
                               <li><a href="css1">CSS1</a></li>
    a[href^=http://]           <li><a href="css2">CSS2</a></li>
                               <li><a href="css3">CSS3</a></li>
                               <li>Basic XPath</li>
                             </ul>
                          </li>
More Attribute Selectors
●   To match an element that possesses a specific attribute, regardless of its value, we
    can use
     ●   form[method] : This matches any <form> element that has explicit method
         attribute
     ●   input[type=text] : This selector matches all input elements with a type of text
     ●   div[title^=my] : This selects elements with title attributes whose value begins with
         my
     ●   a[href$=.pdf] : This selects all links that reference PDF files
     ●   a[href*=jquery.com] : this selectow matches all <a> elements that reference
         jQuery site
Container selector
●    Container selector is useful if we want to
    select an element only if it contains some other
    element
    ●   li:has(a) → This selector matches all <li> elements
        that contain an <a> element
The basic Selectors Supported By jQuery
           Selector                                    Elements
*                             Matches any elements

E                             Matches all elements with tag name

EF                            Matches all elements with tag name F that are descendants of E

E>F                           Matches all elements with tag name F that are direct children of F

E+F                           Matches all elements F immediately preceded by sibling E

E~F                           Matches all elements F preceded by any sibling E

E:has(F)                      Matches all elements with tag name E that have at least one
                              descendent with tag name F

E.C                           Matches all elements E with class name C. Omitting E is the
                              same as *.C

E#I                           Matches elements E with id of I. Omitting E is the same as *#I

E[A]                          Matches all elements E with attribute A of any value

E[A=V]                        Matches all elements E with attribute A whose value is exactly V

E[A^=V]                       Matches all elements E with attribute A whose value begins with V

E[A$=V]                       Matches all elements E with attribute A whose value ends with V

E[A*=V]                       Matches all elements E with attribute A whose value contains V
Selecting by Position
●   Consider we want to select the first link on the page, or every other
    paragraph, or the list item of each list. JQuery supports mechanisms for
    achieving these specific selections.
●   For example :
    ●   a:first → this format of selector matches the first <a> element on the
        page
    ●   p:odd or p:even → this selector matches every odd or even paragraph
    ●   li:last-child → this selector matches the last child of parent elements
Advanced Positional selectors supported by jQuery
                   Selector                         Description

:first                             The first match of the page. Li a:first returns
                                   the first link also under a list item

:last                              The last match of the page. Li a:last returns
                                   the last link also under a list item

:first-child                       The first child element. li:first-child returns
                                   the first item of each child

:last-child                        The last child element. li:last-child returns
                                   the last item of each list

:only-child                        Returns all elements that have no siblings

:nth-child(n)                      The nth child element. li:nth-child(2) returns
                                   the second list item of each list

:nth-child(even|odd)               Even or odd children. li:nth-child(even)
                                   return the even children of each list

:nth-child(Xn+Y)                   The nth child element computed by the
                                   supplied formula.If Y is 0, it may be omitted.
                                   li:nth-child(3n) returns every third item,
                                   whereas li:nth-child(5n+1) return the item
                                   after every fifth element
Advanced Positional selectors supported by jQuery (2)


                 Selector                        Description
:even and :odd                      Even and odd matching elements
                                    page-wide . li:even return every even
                                    list item
:eq(n)                              Th nth matching element
:gt(n)                              Matching elements after (and
                                    excluding) the nth matching element
:lt(n)                              Matching elements before (and
                                    excluding) the nth matching element
Using Custom jQuery Selector

●   What if we want to select all check boxes that
    have been checked by the user ?
    ●   We can use jQuery custom selector : :checked
The jQuery custom filter selectors
        Selector                          Description
:animated           Selects elements that are currently under animated
                    control
:button             Selects any button (input[type=submit],
                    input[type=reset],input[type=reset],
                    input[type=button] or button)
:checkbox           Selects only check box elements
                    (input[type=checkbox])
:checked            Selects only check boxes or radio button that are
                    checked (supported by CSS)
:contains(foo)      Select only elements containing the text foo
:disabled           Select only form elements that are disabled in the
                    interface (supported by CSS)
:enabled            Selects only form elements that are enabled in the
                    interface (supported by CSS)
:file               Select all file elements (input[type=file])
The jQuery custom filter selectors -2
               Selector                                   Description

:header                   Selects only elements that are headers; for example (<h1>) through <h6>
                          elements
:hidden                   Selects only elements that are hidden

:image                    Select form image (input[type=image])

:input                    Select only forms elements (input, select, textarea, button)

:not(filter)              Negates the specified filter

:parent                   Selects only elements that have children (including text), but not an empty
                          elements
:password                 Selects only password elements (input[type=password])

:radio                    Selects only radio elements (input[type=radio])

:reset                    Selects reset buttons (input[type=reset]) or button[type=reset]

:selected                 Select option element that are selected

:submit                   Selects submit buttons (button[type=submit] or input[type=submit])

:text                     Select only text element (input[type=text])

:visible                  Selects only elements that are visible
The jQuery custom filter selectors

●   We can combine selector filters too :

    :checkbox:checked:enabled
Using the :not filter
●   input:not(:checkbox) → Select non-check-box
    <input> elements
●   We cannot :not filter and other filters to find
    selector :

    div :not(p:hidden) → invalid
    div p:not(:hidden) → valied
Jquery XPath Support
●   http://jquery.com/plugins/project/xpath

    TODO : Learn about xpath support later, after we finish the
    book … @_@
Generating new HTML
$("<div class='foo'>I have foo!</div><div>I don't</div>")
 .filter(".foo").click(function() {
   alert("I'm foo!");
 }).end().appendTo("#someParentDiv");
Managing the wrapped element set
Determining the size of the wrapped set


        $('#someDiv')
         .html('There are '+$('a').size()+' link(s) on this page.');




Remember that the set of jQuery wrapped elements acts a lot like an
array. !
Obtaining elements from the wrapped set

●   jQuery allows us to treat the wrapped set as a JavaScript array, so we can
    use simple array indexing to obtain any element in the wrapped list by
    position :
    ●   $('img[alt]')[0] or $('img[alt]').get(0) → get the first element in the set of all
        <img> elements with an alt attribute on the page
Slicing and Dicing the Wrapped Element Set




               Live Demo
Adding more element to the wrapped set

$('img[alt]').add('img[title]')
Adding more element to the wrapped set

●   Let's say that we want to apply a thick border to all <img> elements with alt attributes,
    and then apply a level of transparency to all <img> elements with either alt or title
    attributes


                $('img[alt]').addClass('thickBorder').add('img[title]')
                   .addClass('seeThrough')
Honing the Content of the Wrapped Set




            Live Demo
Q&A
Reference
●   JQuery in Action, Bear Bibeault, Yehuda Katz,
    Manning

Weitere ähnliche Inhalte

Was ist angesagt?

How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
Jeff TUYISHIME
 

Was ist angesagt? (17)

Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Advanced JQuery Selectors
Advanced JQuery SelectorsAdvanced JQuery Selectors
Advanced JQuery Selectors
 
JQuery selectors
JQuery selectors JQuery selectors
JQuery selectors
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Java2
Java2Java2
Java2
 
Event handling
Event handlingEvent handling
Event handling
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
class c++
class c++class c++
class c++
 
Jquery selection optimisation
Jquery selection optimisationJquery selection optimisation
Jquery selection optimisation
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Inner classes
Inner classesInner classes
Inner classes
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Pj01 x-classes and objects
Pj01 x-classes and objectsPj01 x-classes and objects
Pj01 x-classes and objects
 
Event handling
Event handlingEvent handling
Event handling
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 

Andere mochten auch (8)

Exam outline j14
Exam outline j14Exam outline j14
Exam outline j14
 
Rectangular coordinate system
Rectangular coordinate systemRectangular coordinate system
Rectangular coordinate system
 
2.2 Set Operations
2.2 Set Operations2.2 Set Operations
2.2 Set Operations
 
Linear equation in 2 variables
Linear equation in 2 variablesLinear equation in 2 variables
Linear equation in 2 variables
 
Day 9 examples u4f13
Day 9 examples u4f13Day 9 examples u4f13
Day 9 examples u4f13
 
Cartesian coordinate plane
Cartesian coordinate planeCartesian coordinate plane
Cartesian coordinate plane
 
K to 12 - Grade 8 Math Learner Module
K to 12 - Grade 8 Math Learner ModuleK to 12 - Grade 8 Math Learner Module
K to 12 - Grade 8 Math Learner Module
 
20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content
 

Ähnlich wie jQuery BootCamp : Creating the Wrapped Element Set

Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
Mark css syntax & selector
Mark   css syntax & selectorMark   css syntax & selector
Mark css syntax & selector
LearningTech
 

Ähnlich wie jQuery BootCamp : Creating the Wrapped Element Set (20)

VISUAL CHEAT SHEET
VISUAL CHEAT SHEETVISUAL CHEAT SHEET
VISUAL CHEAT SHEET
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1
 
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
 
Jquery Example PPT
Jquery Example PPTJquery Example PPT
Jquery Example PPT
 
J query 1.5-visual-cheat-sheet
J query 1.5-visual-cheat-sheetJ query 1.5-visual-cheat-sheet
J query 1.5-visual-cheat-sheet
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training Material
 
TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training Material
 
TApp Web training material_rev4
TApp Web training material_rev4TApp Web training material_rev4
TApp Web training material_rev4
 
Web Design & Development - Session 6
Web Design & Development - Session 6Web Design & Development - Session 6
Web Design & Development - Session 6
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
JQuery
JQueryJQuery
JQuery
 
TApp Documentation
TApp DocumentationTApp Documentation
TApp Documentation
 
jQuery Selectors
jQuery SelectorsjQuery Selectors
jQuery Selectors
 
Mark css syntax & selector
Mark   css syntax & selectorMark   css syntax & selector
Mark css syntax & selector
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONS
 

Mehr von Wildan Maulana

Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Wildan Maulana
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014
Wildan Maulana
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi Arsip
Wildan Maulana
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
Wildan Maulana
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
Wildan Maulana
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
Wildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Wildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Wildan Maulana
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Wildan Maulana
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Wildan Maulana
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphp
Wildan Maulana
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River Restoration
Wildan Maulana
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan Dasar
Wildan Maulana
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Wildan Maulana
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
Wildan Maulana
 

Mehr von Wildan Maulana (20)

Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018
 
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
 
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam MelonKetahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi Arsip
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphp
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River Restoration
 
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan Dasar
 
Statistik Listrik
Statistik ListrikStatistik Listrik
Statistik Listrik
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
 
Menggunakan AlisJK : Equating
Menggunakan AlisJK : EquatingMenggunakan AlisJK : Equating
Menggunakan AlisJK : Equating
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

jQuery BootCamp : Creating the Wrapped Element Set

  • 1. #2 Day #1 Creating the Wrapped Element Set Wildan Maulana wildan.m@openthinklabs.com http://workshop.openthinklabs.com
  • 2. This Presentation Cover ● Selecting elements to be wrapped by jQuery using selectors ● Creating and placing new HTML elements in the DOM ● Manipulating the wrapped element set
  • 3. Selecting elements for manipulation ● Selectors Lab
  • 4. Using basic CSS selectors ● Selection by an element's ID, CSS class name, tag name, and the DOM hierarchy of the page elements ● a → this selector matches all link (<a>) elements ● #specialD → This selector matches element that have an id of specialID ● .specialClass → This selector matches elements that have the class of specialClass ● a#specialID .specialClass → this selector matches links with an id of specialID and a class of specialClass ● p a.specialClass → This selector matches link with a class of specialClass declared within <p> elements Use Selector labs for exercise using various basic CSS selectors ... $("p a.specialClass")
  • 5. Using child, container, and attribute selectors <ul class="myList"> If we want to select the link to <li><a href="http://jquery.com">jQuery supports</a> <ul> the remote jQuery site basic <li><a href="css1">CSS1</a></li> css selector ul.myList li a will <li><a href="css2">CSS2</a></li> not work .. <li><a href="css3">CSS3</a></li> <li>Basic XPath</li> </ul> </li> The right approach is using <li>jQuery also supports child selectors : <ul> <li>Custom selectors</li> <li>Form selectors</li> </ul> </li> ul.myList > li > a </ul>
  • 6. Attribute Selectors ● To select a link that points to an external site we can use : <li><a href="http://jquery.com">jQuery supports</a> <ul> <li><a href="css1">CSS1</a></li> a[href^=http://] <li><a href="css2">CSS2</a></li> <li><a href="css3">CSS3</a></li> <li>Basic XPath</li> </ul> </li>
  • 7. More Attribute Selectors ● To match an element that possesses a specific attribute, regardless of its value, we can use ● form[method] : This matches any <form> element that has explicit method attribute ● input[type=text] : This selector matches all input elements with a type of text ● div[title^=my] : This selects elements with title attributes whose value begins with my ● a[href$=.pdf] : This selects all links that reference PDF files ● a[href*=jquery.com] : this selectow matches all <a> elements that reference jQuery site
  • 8. Container selector ● Container selector is useful if we want to select an element only if it contains some other element ● li:has(a) → This selector matches all <li> elements that contain an <a> element
  • 9. The basic Selectors Supported By jQuery Selector Elements * Matches any elements E Matches all elements with tag name EF Matches all elements with tag name F that are descendants of E E>F Matches all elements with tag name F that are direct children of F E+F Matches all elements F immediately preceded by sibling E E~F Matches all elements F preceded by any sibling E E:has(F) Matches all elements with tag name E that have at least one descendent with tag name F E.C Matches all elements E with class name C. Omitting E is the same as *.C E#I Matches elements E with id of I. Omitting E is the same as *#I E[A] Matches all elements E with attribute A of any value E[A=V] Matches all elements E with attribute A whose value is exactly V E[A^=V] Matches all elements E with attribute A whose value begins with V E[A$=V] Matches all elements E with attribute A whose value ends with V E[A*=V] Matches all elements E with attribute A whose value contains V
  • 10. Selecting by Position ● Consider we want to select the first link on the page, or every other paragraph, or the list item of each list. JQuery supports mechanisms for achieving these specific selections. ● For example : ● a:first → this format of selector matches the first <a> element on the page ● p:odd or p:even → this selector matches every odd or even paragraph ● li:last-child → this selector matches the last child of parent elements
  • 11. Advanced Positional selectors supported by jQuery Selector Description :first The first match of the page. Li a:first returns the first link also under a list item :last The last match of the page. Li a:last returns the last link also under a list item :first-child The first child element. li:first-child returns the first item of each child :last-child The last child element. li:last-child returns the last item of each list :only-child Returns all elements that have no siblings :nth-child(n) The nth child element. li:nth-child(2) returns the second list item of each list :nth-child(even|odd) Even or odd children. li:nth-child(even) return the even children of each list :nth-child(Xn+Y) The nth child element computed by the supplied formula.If Y is 0, it may be omitted. li:nth-child(3n) returns every third item, whereas li:nth-child(5n+1) return the item after every fifth element
  • 12. Advanced Positional selectors supported by jQuery (2) Selector Description :even and :odd Even and odd matching elements page-wide . li:even return every even list item :eq(n) Th nth matching element :gt(n) Matching elements after (and excluding) the nth matching element :lt(n) Matching elements before (and excluding) the nth matching element
  • 13. Using Custom jQuery Selector ● What if we want to select all check boxes that have been checked by the user ? ● We can use jQuery custom selector : :checked
  • 14. The jQuery custom filter selectors Selector Description :animated Selects elements that are currently under animated control :button Selects any button (input[type=submit], input[type=reset],input[type=reset], input[type=button] or button) :checkbox Selects only check box elements (input[type=checkbox]) :checked Selects only check boxes or radio button that are checked (supported by CSS) :contains(foo) Select only elements containing the text foo :disabled Select only form elements that are disabled in the interface (supported by CSS) :enabled Selects only form elements that are enabled in the interface (supported by CSS) :file Select all file elements (input[type=file])
  • 15. The jQuery custom filter selectors -2 Selector Description :header Selects only elements that are headers; for example (<h1>) through <h6> elements :hidden Selects only elements that are hidden :image Select form image (input[type=image]) :input Select only forms elements (input, select, textarea, button) :not(filter) Negates the specified filter :parent Selects only elements that have children (including text), but not an empty elements :password Selects only password elements (input[type=password]) :radio Selects only radio elements (input[type=radio]) :reset Selects reset buttons (input[type=reset]) or button[type=reset] :selected Select option element that are selected :submit Selects submit buttons (button[type=submit] or input[type=submit]) :text Select only text element (input[type=text]) :visible Selects only elements that are visible
  • 16. The jQuery custom filter selectors ● We can combine selector filters too : :checkbox:checked:enabled
  • 17. Using the :not filter ● input:not(:checkbox) → Select non-check-box <input> elements ● We cannot :not filter and other filters to find selector : div :not(p:hidden) → invalid div p:not(:hidden) → valied
  • 18. Jquery XPath Support ● http://jquery.com/plugins/project/xpath TODO : Learn about xpath support later, after we finish the book … @_@
  • 19. Generating new HTML $("<div class='foo'>I have foo!</div><div>I don't</div>") .filter(".foo").click(function() { alert("I'm foo!"); }).end().appendTo("#someParentDiv");
  • 20. Managing the wrapped element set
  • 21. Determining the size of the wrapped set $('#someDiv') .html('There are '+$('a').size()+' link(s) on this page.'); Remember that the set of jQuery wrapped elements acts a lot like an array. !
  • 22. Obtaining elements from the wrapped set ● jQuery allows us to treat the wrapped set as a JavaScript array, so we can use simple array indexing to obtain any element in the wrapped list by position : ● $('img[alt]')[0] or $('img[alt]').get(0) → get the first element in the set of all <img> elements with an alt attribute on the page
  • 23. Slicing and Dicing the Wrapped Element Set Live Demo
  • 24. Adding more element to the wrapped set $('img[alt]').add('img[title]')
  • 25. Adding more element to the wrapped set ● Let's say that we want to apply a thick border to all <img> elements with alt attributes, and then apply a level of transparency to all <img> elements with either alt or title attributes $('img[alt]').addClass('thickBorder').add('img[title]') .addClass('seeThrough')
  • 26. Honing the Content of the Wrapped Set Live Demo
  • 27. Q&A
  • 28. Reference ● JQuery in Action, Bear Bibeault, Yehuda Katz, Manning