javascript - .replace() is not working like it should -


i trying toggle hidden input element when select element has option. when alerted of variable q, q has no input variable put quite confused why .replace() removes entire string.

function hiddeninput(choice, put) {     var q = put.replace(/./g, "").replace(/#/g, "");     alert(put + "," + q);//alerts .other,     if (choice === q) {         $(put).show();     } else {         $(put).hide();     } } 

any appreciated. jsfiddle has been quite buggy these past few days of previous working fiddles have stopped working, maybe reason.

do realize . match character?

you need escape \ match . , not character.

var q = put.replace(/\./g, "").replace(/#/g, ""); 

and instead of doing 2 replacements can one

var q = put.replace(/[.#]/g,""); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -