I would like to automatically toggle an asp.net control (Textbox) class when a user opens the website on mobile.
I tried the following code it works to get the screen size automatically. but now I want to change or add a new class to the textbox which sets the Textbox width to 100%.
Javascript code
<script type="text/javascript">
window.onload = function () { responsiveFn(); }
function responsiveFn() {
width = $(window).width();
height = $(window).height();
if (width <= 470)
{
var cntltxtInput = document.getElementById(<%=TextBox1.ClientID %>);
cntltxtInput.setAttribute("class", "mobMini");
document.getElementById('widthID').innerHTML += "This is an Iphone S";
}
}
</script>
Asp.net C#
<asp:TextBox ID="TextBox1" runat="server" ></asp:Textbox>
Css Class
<style type="text/css">
.mobMini {
width:100%;
}
</style>
Any ideas?