I am a newbie to jquery and need a little help. I have created the below function which does what I want it to however when I select a textbox every other textbox are automatically selected. How do I change it and pass a parameter from the textbox so only the selected textboxes css changes on focus and blur?
   <script language="javascript" type="text/javascript">
   $(function () {
       $('.myTextBox').focus(function () {
           $('.box.textbox').addClass("active");
       }).blur(funct开发者_如何学Cion () {
           $('.box.textbox').removeClass("active");
       });
   });
</script>
Try with:
   $(function () {
   $('.myTextBox').focus(function () {
       $(this).addClass("active");
   }).blur(function () {
       $(this).removeClass("active");
   });
});
You want to update the object that fired the event so try;
  $(function () {
       $('.myTextBox').focus(function () {
           $(this).addClass("active");
       }).blur(function () {
           $(this).removeClass("active");
       });
   });
Answer for:"Thank you. On my input what do I need to put as the function takes care of both focus and blur <input id="Text1" type="text" attachhow="?" />"
You should add $(document).ready.
Add call it after you html:
<html>
     <%--  <div class="box textbox" style="width: 300px;">
        <div class="topcorners">
            <div>
                <div>
                </div>
            </div>
        </div>
        <div class="middle">
            <div class="left">
                <div class="right">
                    <input type="text" tabindex="1" maxlength="70" size="22" style="width: 292px;" class=" tbox"
                        id="email1" name="email1"/>
                </div>
            </div>
        </div>
</html>
<script type="text/javascript">
    $(document).ready(
    $(function () {
       $('.myTextBox').focus(function () {
           $(this).addClass("active");
       }).blur(function () {
           $(this).removeClass("active");
       });
    );
</script>
sorry to be a real nob. My input looks like this
 <input type="text" tabindex="1" maxlength="70" size="22" style="width: 292px;" class="myTextBox" 
                id="email1" name="email1"/>
When the textbox gets focus or blur occurs, Then the function changes my div class=" not the actual textbox
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论