Using JavaScript-chained programming to implement _javascript techniques for simulating jquery functions

Source: Internet
Author: User

The code is very simple, mainly to provide you with a way of thinking, but also learning JavaScript for so long a small practicing.

Chained programming is the use of multiple operations (multiple lines of code) through the dot number "." Link together to become a code. Chain code usually requires a return value for the operation, but for many operations mostly void, nothing returns, so it is difficult to link up, of course, there are solutions, may not be very elegant. The new idea of chained programming has been used in jquery

Copy Code code as follows:

<span>hello,world! </span>
<script type= "Text/javascript" >
Jq = function (tagName) {
var Tagarr = document.getElementsByTagName (tagName);
var ret = {
Tag:tagarr,
Css:function (attribute, value) {
for (var i = 0; i < this.tag.length; i++) {
This.tag[i].style[attribute] = value;
}
return this;
}
}
return ret;
}
Window.onload = function () {
JQ ("span"). CSS ("Color", "red")
. CSS ("Border", "1px solid green")
. css ("padding", "10px");
}
</script>

If you want to ask, leave a message, we will make progress together.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.