开发者

Have I got the syntax incorrect for this jquery else if statement?

Edit: Question resolved. Syntax error.

Here it is (the if part omitted as I know it is correct)

else if($('.now [name="stuff"]').val() !==''){...}

I want to check the value of the input field withhin the class 'now' and with the name 'stuff' and if the value is not empty, then execute the code within the braces.

have I made a mistake? as my code isn't working.

Edit here is the code in context: 开发者_开发知识库(NOTE - if i delete the else if part the code runs. Currently when I try to run the below code firefox tells me the function which contains the code is undefined)

if($("#form").length==0) {
           ....
    }
    else if($('.now [name="stuff"]').val() !==''){
    $.post("ajax.php", {
            "action": "refresh",
            "app_id": app,
            "type": type,
            "page": page,
            "test": "test";
            "refresh": "1",
            "br": $("#br").val(),
            "brtwo": $('.current [name="brtwo"]').val(),
        }, function(data) {
            $(".current").html(data);
            scrollTo(0, 0);
        });

    }
    else { ... 
     }


Remove the space in the selector: .now[name="stuff"]


When written as .now [name="stuff"] it means: find elements with class="now" and then look within their children for elements with name="stuff".


If I would be using your else if-statement on StackOverflow, I would be doing it like this:

else if( $('textarea.wmd-input[name="post-text"]').val() != '' ) { //do stuff }

Your snippet needs to remove the space between .now and [name="stuff"], like this:

else if($('.now[name="stuff"]').val() !== ''){ //do stuff }

Hope this works out for you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜