简体   繁体   中英

how to replace 'dollar' sign with another character used in jquery?

How will I change the dollar sign (alias for 'jquery') used in jquery with another character. For example

$("#id").css("height","210px");

I want to change this to

*("#id").css("height","210px");

You cannot change $ to * because * is not a valid identifier. But you can change it to a valid one:

(function (foobar) {
    foobar("#whatever").css(....)


})(jQuery);

Given that JavaScript identifiers are unicode, you can try fancy things like for example:

(function (Ω) {
    Ω("#whatever").css(....)
})(jQuery);

dont use * as a variable name please choose valid name here i choose js

var js =jQuery.noConflict(); //by this you can do it

reference jQuery.noConflict()

jQuery comes with a noConflict command which you can assign to a custom variable:

var jq = jQuery.noConflict(true);

This means you can do regular jQuery with your symbol:

jq.css('height', '200px');

You cannot use the asterisk (*) because it is a reserved character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM