1

I have a variable called $places:

    var $places = $('#resultsListing li.place');

When there are more than 0 places the following code add the class .have-results. If there are 0 results the code adds the class .no-results to the body:

body.removeClass("have-results no-results searching");

body.addClass(places.length > 0 ? "have-results" : "no-results");
$("div#busyAnimation").hide();

I would like to add another class called .hasnt-typed-yet. I know it is a horrible name for a class, but that's what I want to accomplish; add that class to the body if the user hasn't typed yet in the input.

Any suggestions to accomplish this?

3 Answers 3

2
var textbox_text = $("#searchbox").val(); 
if(textbox_text !== '' ){
    body.addClass(places.length > 0 ? "have-results" : "no-results");
}else{
   body.addClass('hasnt-typed-yet');
}
$("div#busyAnimation").hide();
Sign up to request clarification or add additional context in comments.

Comments

0
if($('input').val() == '')
    $('body:first').addClass('hasnt-typed-yet')
else
    $('body:first').removeClass('hasnt-typed-yet')

Comments

0
$textbox = $('#searchbox');
$body = $('body').filter(':first');
$places = $('#resultsListing li.place');

$textbox.keyup(function() {
    if($(this).val() == '') $body.addClass('hasnt-typed-yet');
    else $body.removeClass('hasnt-typed-yet');
});

$body.addClass($places.length > 0 ? 'have-results' : 'no-results');
$('#busyAnimation').hide();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.