Sree KS
Sree KS

Reputation: 1343

Is Using Javascript inside a jQuery function is a bad practice?

I know basics of both jQuery and JavaScript.I would like to follow a good coding practice. Is using JavaScript inside a jQuery function is a bad practice?

For exapmle:

$(document).ready( function() {
    $('#dqualification').change(function() {
        document.getElementById("demo").innerHTML = "Resolve following errors"; 
    });
});

Upvotes: 1

Views: 227

Answers (2)

100pic
100pic

Reputation: 387

Nope, its fine, and it's done all the time.

Consider:

$("#myDiv").on("click", function(){
    var a = this;
});

The line var a = this; is pure JavaScript. There is no "jQuery Version" of var a = this;.

jQuery provides convenient ways of doing things in JavaScript that might be difficult to write and code yourself in pure JavaScript. It doesn't replace JavaScript, it just 'adds to it'.

Remember, jQuery is just a JavaScript library. So everything ends up as JavaScript at the end of the day.

Upvotes: 3

eisbehr
eisbehr

Reputation: 12452

It is not directly bad practice, it is more a bit inconsistend. Both is javascript. But why would you do things like in your example? If you have jQuery available, you could use it!

$(function() {
    $('#dqualification').change(function() {
        $("#demo").html("Resolve following errors");
    });
});

Upvotes: 2

Related Questions