Skip to main content

Posts

Showing posts with the label Website

jQuery Syntax

  jQuery Syntax The jQuery syntax is tailor-made for  selecting  HTML elements and performing some  action  on the element(s). Basic syntax is:  $( selector ). action () A $ sign to define/access jQuery A ( selector ) to "query (or find)" HTML elements A jQuery  action () to be performed on the element(s) Examples: $(this).hide()  - hides the current element. $("p").hide()  - hides all <p> elements. $(".test").hide()  - hides all elements with class="test". $("#test").hide()  - hides the element with id="test".

Adding jQuery

  Adding jQuery to Your Web Pages There are several ways to start using jQuery on your website. You can: Download the jQuery library from jQuery.com Include jQuery from a CDN, like Google Downloading jQuery There are two versions of jQuery available for downloading: Production version - this is for your live website because it has been minified and compressed Development version - this is for testing and development (uncompressed and readable code) Both versions can be downloaded from  jQuery.com . The jQuery library is a single JavaScript file, and you reference it with the HTML  <script>  tag (notice that the  <script> tag should be inside the  <head>  section): < head > < script  src ="jquery-3.6.0.min.js" > < /script > < /head > Tip:  Place the downloaded file in the same directory as the pages where you wish to use it. jQuery CDN If you don't want to download and host jQuery yourself, you can inc...

CSS Color

In CSS, a color can be specified by using a predefined color name: CSS/HTML support 140 standard color names. Tomato Orange DodgerBlue MediumSeaGreen Gray SlateBlue Violet LightGray CSS Background Color You can set the background color for HTML elements: Hello World Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Example < h1  style ="background-color:DodgerBlue;" > Hello World < /h1 > < p  style ="background-color:Tomato;" > Lorem ipsum... < /p > Try it Yourself » CSS Text Color You can set the color of the text: Hello World Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tati...

CSS Comments

Comments are used to explain the code and may help when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment is placed inside the  <style>  element, and starts with  /*  and ends with  */ : Example /* This is a single-line comment */ p  {   color :  red ; } Try it Yourself » You can add comments wherever you want in the code: Example p  {   color :  red ;    /* Set text color to red */ } Try it Yourself » Comments can also span multiple lines:  Example /* This is a multi-line comment */ p  {   color :  red ; } Try it Yourself » HTML and CSS Comments From the HTML tutorial, you learned that you can add comments to your HTML source by using the  <!--...-->  syntax. In the following example, we use a combination of HTML and CSS comments: Example < !DOCTYPE  html > < html > < head > < style > p  {   color : ...

Three Ways to Insert CSS

There are three ways of inserting a style sheet: External CSS Internal CSS Inline CSS External CSS With an external style sheet, you can change the look of an entire website by changing just one file! Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Example External styles are defined within the <link> element, inside the <head> section of an HTML page: < !DOCTYPE  html > < html > < head > < link  rel ="stylesheet"  href ="mystyle.css" > < /head > < body > < h1 > This is a heading < /h1 > < p > This is a paragraph. < /p > < /body > < /html > Try it Yourself » An external style sheet can be written in any text editor, and must be saved with a .css extension. The external .css file should not contain any HTML tags. Here is how the "mystyle.css" file looks: "mystyle.css" body  {   backg...

The CSS class Selector

The class selector selects HTML elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the class name. Example In this example all HTML elements with class="center" will be red and center-aligned:  .center  {   text-align :  center ;   color :  red ; } Try it Yourself » You can also specify that only specific HTML elements should be affected by a class. Example In this example only <p> elements with class="center" will be red and center-aligned:  p.center  {   text-align :  center ;   color :  red ; } Try it Yourself » HTML elements can also refer to more than one class. Example In this example the <p> element will be styled according to class="center" and to class="large":  < p  class ="center large" > This paragraph refers to two classes. < /p > Try it Yourself » Note:  A class name cannot start with a numbe...