This article, the collection of some of the more commonly used JavaScript functions, I hope to learn from the friends of JS help.
22. Replace elements
$ (document). Ready (function () {
$ (' #id '). ReplaceWith ('
<div>i have been replaced</div>
');
});
jquery time-Delay loading function
$ (document). Ready (function () {
window.settimeout (function () {
//do something
}, 1000);
24. Remove Word function
$ (document). Ready (function () {
var el = $ (' #id ');
El.html (el.html (). Replace (/word/ig, ""));
25. Verify that the element exists in the JQuery object collection
$ (document). Ready (function () {
if ($ (' #id '). Length) {
//do Something
}
});
26. Make the entire DIV clickable
$ (document). Ready (function () {
$ ("div"). Click (function () {
//get the URL from href attribute and launch the url< c3/>window.location=$ (This). Find ("a"). attr ("href"); return false;
}); /How to Use<div><a href= "index.html" >HOME</A></DIV>});
Convert between ID and class
When changing the window size, switch between ID and class
$ (document). Ready (function () {
function checkwindowsize () {
if ($ (window). Width () > 1200) {
$ (' body '). AddClass (' large ');
} else {
$ (' body '). Removeclass (' large ');
}
$ (window). Resize (checkwindowsize);
});
28. Cloning objects
$ (document). Ready (function () {
var cloned = $ (' #id '). Clone ()/How to Use<div id=id></div>};
29. Make the element reside in the middle of the screen
$ (document). Ready (function () {
jQuery.fn.center = function () {
this.css ("position", "absolute");
This.css ("Top", ($ (window). Height ()-this.height ())/2+$ (window). scrolltop () + "px");
This.css ("Left", ($ (window). Width ()-this.width ())/2+$ (window). ScrollLeft () + "px");
return this;
}
$ ("#id"). Center ();
30. Write your own selector
$ (document). Ready (function () {
$.extend ($.expr[': '), {
morethen1000px:function (a) {return
$ (a). Width () > 1000;
}
});
$ ('. box:morethen1000px '). Click (function () {
//Creating a simple JS alert box
alert (' The element so you have C Licked is over 1000 pixels wide ');
};
31. Number of statistical elements
$ (document). Ready (function () {
$ ("P"). Size ();
});
32. Use your own bullets
$ (document). Ready (function () {
$ ("ul"). AddClass ("replaced");
$ ("ul > Li"). Prepend ("\u2012"); How to use
ul. replaced {list-style:none}
});
33. Refer to the jquery Class library on Google mainframe
Example 1
<script src= "Http://www.google.com/jsapi" ></SCRIPT>
<script type=text/ javascript>
google.load ("jquery", "1.2.6");
Google.setonloadcallback (function () {
//do something
});
</script><script type=text/javascript src= "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/ Jquery.min.js "></SCRIPT>
//Example 2: (The best and fastest way)
<script Type=text/javascript Src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" ></SCRIPT>
34. Disable jquery (animation) effects
$ (document). Ready (function () {
JQuery.fx.off = true;
});
35. Conflict resolution with other JavaScript class libraries
$ (document). Ready (function () {
var $jq = jquery.noconflict ();
$JQ (' #id '). Show ();
The above is the entire content of this article, like the collection bar!