Results 1 to 3 of 3

Thread: How to Show a Div in JavaScript or JQuery

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    How to Show a Div in JavaScript or JQuery

    Good Evening All

    I have a small issue here. I have a Div inside a TD that is defined like this

    Code:
     <td    >
                    <div id="divGoogleEarthMap" runat="server" style="display:none" 
                        >
                        <asp:HiddenField ID="HiddenField1" runat="server" />
                        <asp:ImageButton ID="GoogleEarthMap" runat="server" Height="100px" 
                            OnClientClick="javascript:showimage('GoogleEarthMap'); return false;" 
                            Width="100px" />
                    </div>
                </td>
    now the display style of this div is hidden. so i have a Javascript that runs when i close my popup. the first thing that javascript does is to populate two textboxes and show this div. It populate the textboxes nicely , but it fails to show or unhide the div. i have tried to set of code example using the normal javascript and also JQuery as depicted below


    Code:
                    $('#divGoogleEarthMap').css('display', "block;");
    and


    Code:
     var div = document.getElementById("divGoogleEarthMap");
                    div.style.display = "block";
    or


    Code:
             document.getElementById('divGoogleEarthMap').style.display = 'block';
    but still my Element cant be displayed.

    Please note that i have a Sample Project that i can be supplied on request


    Thanks

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: How to Show a Div in JavaScript or JQuery

    Your div has a runat="server". That means its ID will change at runtime. It will not be divGoogleEarthMap, it will be something like ctl00_blah_blah_divGoogleEarthMap.

    Either remove the runat="server", after which this will work

    Code:
     $('#divGoogleEarthMap').css('display', "block");
    Or generate the hide/show JS from the codebehind.

    Code:
    showDivJs = "$('#" + divGoogleEarthMap.ClientID + "').css('display','block');";

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: How to Show a Div in JavaScript or JQuery

    in jQuery you can also do a partial match (very useful for controls with runat=server.)

    Code:
    $('input[id$="_divGoogleEarthMap"]').css('display', 'block);

Posting Permissions

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



Click Here to Expand Forum to Full Width