简体   繁体   中英

change type of input element in jquery not working in IE

if($jq(this).text() == "Show") {
    $jq('#password')[0].type = "text";
} else {
    $jq('#password')[0].type = "password";
}

In my program, I am changing type of password input field on clicking hide or show password button.

the above code works fine with all the browsers except IE.

anyone plz help me with solution. Thanks

Try

.attr()

if($jq(this).text() == "Show") {
    $jq('#password').attr("type","text");
} else {
    $jq('#password').attr("type","password");
}

or better use .prop

if($jq(this).text() == "Show") {
    $jq('#password').prop("type","text");
} else {
    $jq('#password').prop("type","password");
}

Read .prop() vs .attr()

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