+ Reply to Thread
Results 1 to 2 of 2

Thread: trigger javascript on anchor click

  1. #1

    trigger javascript on anchor click

    I have a situation where I am dynamically adding some content to popup box (which is a div) on my page from c#
    Code:
    HtmlGenericControl content = new HtmlGenericControl();
    content.InnerHtml = "<a id='close' href='' onclick='action()'>close</a><span>Some text here</span>";
    divcontrl.Controls.Add(content);
    divcontrl.Attributes.Add("class", "myclass");
    
    javscript method:function action() {$('.myclass').hide();}
    If I keep href='' on anchor it's closing the window but reloading the page, if I remove it not closing the window , i hope you guys help me with that

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    35
    You should be doing that :
    Code:
    href="javascript:void(0);" onclick='return action()'
    And add return to the js function .
    Code:
    function action() {
        $('.myclass').hide();
        return false;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts