Home > Web Front-end > JS Tutorial > body text

Comparative examples of js and jq

小云云
Release: 2018-03-26 16:26:11
Original
1564 people have browsed it

This article mainly shares with you the comparative examples of js and jq, mainly in the form of code, hoping to help everyone.

1. Traverse / event

//  js
var liList = document.querySelector('ul').querySelectorAll('li');
for(var i = 0; i < liList.length; i++){
    liList[i].onclick = function () {

    }
}
// jq
$(&#39;.optionUl li&#39;).each(function () {
    $(this).click(function () {
        
    });
})
Copy after login

2. Get custom properties

// js
var id = document.querySelector(&#39;.demo&#39;).dataset.id;

// jq
var id = $(&#39;.demo&#39;).data(&#39;id&#39;);
Copy after login

3. Set css properties

//jsdocument.querySelector(&#39;.demo&#39;).style.color = "red";//jq$(&#39;.demo&#39;).css("display")
Copy after login

4. Get src

//jq var it = $(&#39;.captcha img&#39;).attr("src"); var it = $(&#39;.captcha img&#39;)[0].src;
Copy after login

5. Change className

//jsdocument.querySelector(&#39;.demo&#39;).className = "list";//jq$(&#39;.demo&#39;).css("display")
Copy after login

Related recommendations:

JS and jquery knowledge points summary

JS and jQuery registration information The verification function implementation code

What is the difference between JS and JQUERY

The above is the detailed content of Comparative examples of js and jq. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!