jQuery code works for console but not in-page.

Posted by justSteve on Stack Overflow See other posts from Stack Overflow or by justSteve
Published on 2010-04-01T15:55:33Z Indexed on 2010/04/01 16:03 UTC
Read the original article Hit count: 221

Filed under:
|
|

I have a form element defined as:

<div class="field">
    <div class="name">
        <label for="User_LastName">
            Last name: <span class="asterisk">*</span></label>
    </div>
    <div class="value">
        <%= Html.TextBox("User.LastName", Model.LastName)%>
        <%= Html.ValidationMessage("User.LastName")%>
    </div>
</div>

and a jQuery selector that is supposed to detect when the input gets focus and highlight the parent:

    $("input").focus(function() {
    //watching for an event where an input form comes into focus
        $(this)
    .parent()
        .addClass("curFocus")
    .children("div")
        .toggle();
    });

If i paste this code into firebug's console - things work as planned. However, i'm running this from a 'RenderPartial' .net mvc page. Other jQuery code sitting within the same $(document).ready(function() { block work correctly.

The form uses html helpers to generate the inputs which might complicate the process somewhat - but even so... i'm seeing correct behavior when that code's in console but not in a 'real-time' page.

How do i troubleshoot this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about forms