Home > Web Front-end > JS Tutorial > Solve the problem of conflict between custom $(id) method and jquery selector $_jquery

Solve the problem of conflict between custom $(id) method and jquery selector $_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:44:42
Original
996 people have browsed it

Usually just change your function name:

It is easier and simpler, just replace it in batches.

First enter the code:

Copy code The code is as follows:

var $= function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};

This code imitates jquery's custom id selector method, but because jquery selector also uses the "$", if you quote jquery and use this method, the page will report an error. The best solution is to modify it Change "$" to "getId(id)" in your own method;

Copy code The code is as follows:

ar getId = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template