Web Programming Language

Slides:



Advertisements
Similar presentations
JavaScript & jQuery JavaScript and jQuery introduction.
Advertisements

The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
JQuery A Javascript Library Hard things made eas(ier) Norman White.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
Lecture Cascading Style Sheets (CSS) Internal Style Sheets Classes.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
JS: Document Object Model (DOM)
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
CSS/Photoshop Layouts – Quiz #7 Lecture Code:
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
JQuery Youn-Hee Han
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
Eric Meyer on CSS Project 12 pp Project 12 Files.
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
Create Element, Remove Child. The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Making web pages interactive with JavaScript.
Chapter 1: Intro to HTML Section 1: HTML Structure Presentation Section 2: Layout of an HTML File Section 3: Working with Lists & Tables Section 4: HTML.
.. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between HTML and JavaScript. The jQuery library.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Java Script and the DOM DOM stands for: –The Document Object Model When a browser reads a web page, it converts it’s contents from HTML into a hierarchical.
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
Fall 2016 CSULA Saloni Chacha
Cascading Style Sheets (CSS) Internal Style Sheets Classes
Working with Cascading Style Sheets
CSS Box Model.
LAB Work 01 MBA 61062: E-Commerce
4.01 Cascading Style Sheets
-By Yogita Nirmal.
CSS Rule Selector Declaration Block Value Attribute Name body {
Mansoor Ahmed Bughio.
CSS.
Introduction to Web programming
Cascading Style Sheets (Layout)
Intro to CSS CS 1150 Fall 2016.
Document Object Model (DOM): Objects and Collections
Intro to CSS CS 1150 Spring 2017.
HTML A brief introduction HTML.
CSS Borders and Margins.
Software Engineering for Internet Applications
CSS and Box Model.
DynamicHTML Cascading Style Sheet Internet Technology.
JQuery with ASP.NET.
Introduction to Programming the WWW I
Document Object Model (DOM): Objects and Collections
Web Programming Language
DynamicHTML Cascading Style Sheet Internet Technology.
..
Introduction to HTML5.
Training & Development
Understand basic HTML and CSS terminology, concepts, and basic operations. Objective 3.01.
E-commerce Applications Development
Web Application Development
Web Programming Language
4.01 Cascading Style Sheets
CSS Box Model.
CSS Box Model.
Web Client Side Technologies Raneem Qaddoura
Web Programming and Design
ជំពូកទី៤ Jquery​ Traversing មេរៀនទី២៖ ​​ Sibling និង Filtering
Presentation transcript:

Web Programming Language Chapter 10

JQuery and the DOM The Document Object Model Manipulating the DOM Navigating the DOM

DOM? The DOM is a structured model of a webpage. While the  browser par ses a version of the document, the DOM provides  a neutral interface  for scripts to dynamically access and  change the content, structure a nd style of the document. 

DOM? <html>     <head>       <title>Simple Page</title>     </head>     <body>       <div class="simple">         <h1>My Heading</h1>         <p>My Paragraph</p>       </div>     </body>  </html> 

DOM?

DOM?

text() Return (OR CHANGE) contents of an element <script>      $(document).ready(function(){       $("#button").click(function(){         alert($("#myparagraph").text());       });     });  </script> 

text() <script>      $(document).ready(function(){       $("#button").click(function(){         $("#myparagraph").text(“Changed the text to this”);       });     });  </script>

html() <script>      $(document).ready(function(){       $("#button").click(function(){         alert($("#myparagraph").text());         alert($("#myparagraph").html());       });     });  </script>  <p id=”myparagraph”><strong>Some text</strong></p>

html() <script>      $(document).ready(function(){         $("#myparagraph").html(“<strong>Hello World</strong>”);     });  </script>  <p id=”myparagraph”>Hello World</p> 

val() <script>      $(document).ready(function(){       $("#submit").click(function(){         if($("#pass1").val().length < 8) {  alert(“Password must be at least 8 letters long”);  }       });     });  </script> 

attr() <script>      $(document).ready(function(){       $("#submit").click(function(){         $("#mylink").attr({           "href" : "http://www.google.com",           "title" : "Google"         });       });     });  </script> 

Add elements to a page Adding to a Page before() Adds content before the specified element after() Adds content after the specified element prepend() Adds content at the start of the specified element append() Adds content at the end of the specified element

Add Elements to a Page <html><head><title>Add</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></scrip t> <script> $(document).ready(function() { $('#mydiv').before("BEFORE"); $('#mydiv').after("AFTER"); $('#mydiv').prepend("PREPEND"); $('#mydiv').append("APPEND"); }); </script> </head><body> <div id="mydiv">Original Text</div> </body></html>

Removing Elements Check out:- remove() And empty()

Adding Class <script> $(document).ready(function(){ $(“#mydiv”).addclass(“subheading”); }); </script> N.B. removeclass()

css() <script> $(document).ready(function(){ $("button").click(function(){ $("p").css("background-color","green"); }); }); </script>

The Box Model

Navigating the DOM <html><head> <style> .box { display: block; border: 2px solid #ddd; padding: 2px; margin: 2px; } </style> </head><body> <div class="box grandparent" id="grandparent">Grandparent <div class="box" id="parent">Parent <div class="box" id="child1">Child 1</div> <div class="box" id="child2">Child 2</div> <div class="box" id="child3">Child 3</div> <div class="box" id="child4">Child 4</div> </div> </div> </body></html>

parent() <script> $(document).ready(function() { $('#child1').parent().css({"border":"2px solid black"}); }); </script>

parents() <script> $(document).ready(function() { $('#child1').parents().css({"border":"2px solid black"}); }); </script>

parentsUntil() <script> $(document).ready(function() { $('#child1').parentsUntil("body").css({"border":"2px solid black"}); }); </script>

Particular Parents? <script> $(document).ready(function() { $('#child1').parents("div").css({"border":"2px solid black"}); }); </script>

children() <script> $(document).ready(function() { $('#grandparent').children().css({"border":"2px solid black"}); }); </script>

More children() <script> $(document).ready(function() { $('#grandparent').children().children().css({"border":"2px solid black"}); }); </script>

find() <script> $(document).ready(function() { $('#grandparent').find("#child2").css({"border":"2px solid black"}); }); </script>

find(*) <script> $(document).ready(function() { $('#grandparent').find("*").css({"border":"2px solid black"}); }); </script>

More traversal! Traversing Across the DOM siblings() Identifies all other elements with the same parent next() Identifies the next element with the same parent nextAll() Identifies all subsequent elements with the same parent nextUntil() Identifies all subsequent elements with the same parent, until one that satisfies a specified selector prev() Identifies the previous element with the same parent prevAll() Identifies all previous elements with the same parent prevUntil() Identifies all previous elements with the same parent, until one that satisfies a specified selector.

first() <script> $(document).ready(function() { $('div').first().css({"border":"2px solid black"}); }); </script>

last() <script> $(document).ready(function() { $('div').last().css({"border":"2px solid black"}); }); </script>

eq() <script> $(document).ready(function() { $('div').eq(2).css({"border":"2px solid black"}); }); </script>

Key Points The Document Object Model, or DOM, represents the structure of a webpage with each element on the page an object that are related in a tree structure. JQuery offers a variety of functions that make manipulating the DOM straightforward. Existing DOM element can be changed, in terms of their text, their HTML, the values and their attributes. New elements can be added to the DOM, and elements can be removed. The DOM can be navigated, once a selector has been targeted, JQuery makes it easy to move up, down or across the tree to move to another element.