How reddit clears its search box

Discussion in 'HTML & Website Design' started by bonecone, Mar 2, 2010.

  1. #1
    When you load www.reddit.com the searchbox contains the words "search reddit". Once it receives the focus by tabbing or clicking, the contents are cleared. However, there is no onfocus event, onclick event or any other script within the tag for this textbox. How is a textbox cleared without explicitly using an event?
     
    bonecone, Mar 2, 2010 IP
  2. canadianguy_001

    canadianguy_001 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's done with jQuery. So rather than there being an onfocus/onclick attribute in the input tag, there is an event listener in an external script that waits for you to click it and then removes the text. Something like this

    $('#mySearchBox').focus(function(){
    $(this).val('');
    });
     
    canadianguy_001, Mar 2, 2010 IP