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 $('.optionUl li').each(function () { $(this).click(function () { }); })
2. Get custom properties
// js var id = document.querySelector('.demo').dataset.id; // jq var id = $('.demo').data('id');
3. Set css properties
//jsdocument.querySelector('.demo').style.color = "red";//jq$('.demo').css("display")
4. Get src
//jq var it = $('.captcha img').attr("src"); var it = $('.captcha img')[0].src;
5. Change className
//jsdocument.querySelector('.demo').className = "list";//jq$('.demo').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!