In order to build jQuery function
on a website, you will need to apply several steps which will be explained more
below. But before you go to the next discussion, you should firstly pay
attention to this introduction. For
beginners, choosing the way for declaring JavaScript function could be quite
confusing. You need to know why and how you use them in writing jQuery code.
This is because there are some different ways for such purposes using jQuery or
JavaScript.
From Loading JavaScript Library up to Putting Things Off Together
Apparently, jQuery can be used to
build the web widget as well. Web Widgets
are component of web page chunk which is provided to another people with the
purpose of displaying the data for your site on their page. It typically
contains of HTML, JavaScript, and CSS in slightly complex mixture. You will
probably want to make that complexity hidden. Widget which is developed could
also be embedded within web page using only two tags of HTML. Code which is
referenced with script tag is going to take care the downloading of different
assets and update container’s content.
Now, let’s back to the topic of
how to build jQuery function in the website. The following description might
help you to explain the steps ranging from loading the JavaScript library until
putting things together.
·
Load JavaScript
library
First step to follow is that you
have to load JavaScript in library. Create
local variable to hold your jQuery version and then check presence of jQuery
version you need. You will be strict about version number. However, you could
use regular expression that can match the version of major number. You can do
this once you have tested the code with some versions. You can create script
element simply that points to library file URL. This is needed for loading the
library. When there is a problem of page which is written poorly and has no
head, you can simply append the script tag to the element of document.
·
Load the data from
site
This step is called “load data from our site”. In this point, you will
load JavaScript file taken from server using the request of GET HTTP and then
you execute it. You just can use the regular AJAX if host page is located in
same domain. There might be security restriction as well. But the browser
allows the use of script tags to deal with security restriction.
·
Load the CSS
Another step you need to follow
is loading CSS. For loading the stylesheets,
you can create link tag by using JavaScript. If you want to dynamically load
CSS stylesheets after HTML page you have has loaded, you can use jQuery to help
you achieve that purpose through few code line.
·
Put things together
The last step to do is putting things off together. After you have seen
different bits, you could put things together and then build simple example.
When you find some errors in host pages later, you are suggested to write the
custom code in order to test whether the pages are ready or not.
0 komentar:
Posting Komentar