How would I remove the $ marks from this JavaScript code?

I forgot how this is done.

Code: https://jsfiddle.net/3jr8otmg/1/

$(document).ready(function () {
    $("#btn").on("click", function () {
        var viewport = 640;
        if ("" != $("#input").val()){
            viewport = $("#input").val();
        }
        var str = $('#data').val();
        var result = str.replace(/(\d*\.\d+|\d+)px/gi, function (px) {
            var pointNum = parseFloat(px);
            var x = convertPXToVW(pointNum, viewport);
            return x + 'vw';
        });
        $('#result').val(result).select();
        document.execCommand("copy");

        $(".dasaochep").addClass("fadeIn"),
        $(".dasaochep").removeClass("fadeOut"),
        setTimeout(function () {
            $(".dasaochep").removeClass("fadeIn"),
            $(".dasaochep").addClass("fadeOut");
        }, 500);
    });
});
function convertPXToVW(px, width) {
    var a = px * (100 / width);
    return Math.round(a * 10000) / 10000;
}

Why would you want to?

That is how it knows to use the jQuery module. That being said, I think that the $ is just a synonym for “jQuery” so I think that you can just do:

jQuery(document).ready(function () {
 // ...

If that doesn’t work, you could always put:

const jQuery = _;

or

const jQ = _;

or whatever at the top.

I would need to replace the jquery with pure javascript.

OK, well, that is a whole different question. “How do I get rid of the $” and how to I completely remove jQ from a project are different questions.

That is a complicated question. I would search for links that discuss this.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.