I want to use the Javascript selector document.querySelector insted of $ or jQuery jQuery selector but I want to combine the Javascript selector with jQuery functions (like .getJSON(), .html(), .append() , etc.).
For example:
$.getJSON("list.json", function(data) {
document.querySelector("#content").html(data.name);
});
Here when I use the document.querySelector I get Uncaught TypeError: undefined is not a function and when I use $ I don't get any error.
jsFiddle Test
Is it possible to run jQuery and Javascript together?
Thanks!
$(document.querySelector("#content")).test(data.name), but it makes no sense. And won't work in browsers that don't supportquerySelector.this.idis faster than$(this).attr('id'). Keep in mind that when mixing, code might get confusing. Either way, it's your personal choice.