Home >Web Front-end >JS Tutorial >Comparative examples of js and jq

Comparative examples of js and jq

小云云
小云云Original
2018-03-26 16:26:111612browse

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 () {
        
    });
})

2. Get custom properties

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

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

3. Set css properties

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

4. Get src

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

5. Change className

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

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!

Statement:
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