admin管理员组

文章数量:1394076

I'm using Jade and my HTML template looks something like this

.container
        .row
          form
            .span3.input-append(style='margin-top: 30%; margin-left: 30%;')
              input#main_search.span2(style='height: 26px; width: 400px;', type='text', id='searchBox' )
              input.btn.btn-large.btn-primary(type='button', value='search', id='searchButton')
include partials/scripts

And my scripts.jade includes a bunch of Javascript functions including

$(document).ready(function() {
    console.log('foo');
    $("searchButton").click(function() {
        console.log('sup');
            window.location.replace("");
    });
});

Console output -

foo

I'm using Jade and my HTML template looks something like this

.container
        .row
          form
            .span3.input-append(style='margin-top: 30%; margin-left: 30%;')
              input#main_search.span2(style='height: 26px; width: 400px;', type='text', id='searchBox' )
              input.btn.btn-large.btn-primary(type='button', value='search', id='searchButton')
include partials/scripts

And my scripts.jade includes a bunch of Javascript functions including

$(document).ready(function() {
    console.log('foo');
    $("searchButton").click(function() {
        console.log('sup');
            window.location.replace("http://stackoverflow.");
    });
});

Console output -

foo
Share Improve this question asked Jul 3, 2013 at 20:13 NarabhutNarabhut 8374 gold badges13 silver badges30 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

Change searchButton to #searchButton. It's an ID, so must be prefixed with #.

You are missing # in the id selector. it should be #searchButton instead of searchButton

 $("#searchButton").click(function() {
        console.log('sup');
            window.location.replace("http://stackoverflow.");
    });

Also not that even you have incorrect selector $("searchButton") which does not find any elements jquery will not throw any error while registering the click handler on them unlike document.getElementById where the result will be undefined and accessing the properties will throw an error.

本文标签: javascriptRedirect to another webpage in jQuery via button clickStack Overflow