Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    98
    Thanks
    6
    Thanked 7 Times in 7 Posts

    jQuery val() problem

    Why is it that code processing stops mid-chain when it encounters .val('...'), yet continues when .val('...') is replaced with .attr('value', '...')?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,627
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    Well, maybe if you let us guess your code until we’re dead we’ll eventually find out.

  • #3
    New Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    98
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Here's the code:
    $(contextNode).children('div[name="btnAddItem"]').addClass(addItemClass).children('.button').attr('value', btnAddItemValue).attr('onclick', fn);

    Ty for moving it to the correct forum.
    Last edited by sbhmf; 06-24-2013 at 12:28 AM.

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,246
    Thanks
    12
    Thanked 340 Times in 336 Posts
    Quote Originally Posted by sbhmf View Post
    Why is it that code processing stops mid-chain when it encounters .val('...'), yet continues when .val('...') is replaced with .attr('value', '...')?
    maybe because those elements are no form control elements?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,627
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    sbhmf, that snippet still doesn’t tell us anything about the context in which the script is used. Please provide all your code, that is HTML and JS.

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    $(contextNode).children('div[name="btnAddItem"]').addClass(addItemClass).children('.button').attr('value', btnAddItemValue)
    are you sure you are targeting an input of some kind? the children elements of .button are form inputs?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •