Span tag onclick loads blank page?


I’ve got a span tag:

<span id="myBtnfb"
    class="demo" onclick="open()">
    <span class="icon">&nbsp;</span>
    <span class="">Testing</span>

and some javascript

  function open() {

Now, what I want to happen is when the span is clicked, it fires the function “open”. What seems to happen though is it just reloads the page but brings back a blank page. Any ideas?


open() is a native JavaScript function, which opens a new page (in this case blank since there’s no params specified):

Just rename your function to something like openAlert():

Also, @Ian mentioned in the comments that in JSFiddle, it’s best to change the JavaScript wrap to "No wrap – in " so that the code works.

Answered By – Alfred Xing

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published