Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Resetting drop downs inside of a div

Resetting drop downs inside of a div

Scheduled Pinned Locked Moved JavaScript
javascriptquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aptiva Dave
    wrote on last edited by
    #1

    I know that there is an easy way to do this, but I'm so green on javascript programming that I'm missing something. Anyway, I have a div with some selects in it and I want to reset them all back to the first option. Here is my current code:

    $("#newAuction").children('select').each(function () {
    $(this).find('option:first').attr('selected', 'selected');
    });

    This isn't looping through all of the selects (there are four in this div) and resetting them to the first option. What am I doing wrong?

    Z 1 Reply Last reply
    0
    • A Aptiva Dave

      I know that there is an easy way to do this, but I'm so green on javascript programming that I'm missing something. Anyway, I have a div with some selects in it and I want to reset them all back to the first option. Here is my current code:

      $("#newAuction").children('select').each(function () {
      $(this).find('option:first').attr('selected', 'selected');
      });

      This isn't looping through all of the selects (there are four in this div) and resetting them to the first option. What am I doing wrong?

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      $('select option:first-child').attr("selected", "selected");

      This will do all on a page. If you specifically want just the ones is a particular div then you can add that into the selector.

      There are only 10 types of people in the world, those who understand binary and those who don't.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups