0

I have made a search bar that I want to show when user will click on search image that is list item as

<li class="item" onclick="showSearch()"><img id="search" src="images/search.png" ></li>

I set the visibility to hidden in HTML as

<div id="bar_search" style="visibility:hidden;">

have a function as

function showSearch () {
    document.getElementById("bar_search").style.visibility = "visible"; 
}

but when i click on list item it does not show however hidden property working fine.

where I'm making mistake please tell me, thanks

Update: content in the div

<div id="bar_search" style="visibility:hidden;">
        <img id="searchbar" src="images/searchBar.png">
        <div id="searchDec">
            <input type="text">
            <button ><b>Search</b></button>
        </div>
    </div>
12
  • 3
    Works for me jsbin.com/hemeticupu Commented Aug 26, 2015 at 21:33
  • 2
    There is no obvious error in the code. Do you get any error message? Commented Aug 26, 2015 at 21:35
  • 1
    have you checked that there is an element with an id attribute bar_search? You can always use console.log to see what's happening. For instance console.log(document.getElementById('bar_search').length));if not 1 or more then there are no elements with the id bar_search. Commented Aug 26, 2015 at 21:35
  • Place your code at the end of the html, before closing body tag... Btw, what is vanilla JS alternative for $(document) ready? :) Commented Aug 26, 2015 at 21:35
  • @nevermind — Why? The event handler is bound with an onclick attribute. Commented Aug 26, 2015 at 21:38

2 Answers 2

1

Try setting the property through your style sheet and see if you can't get it to change with the event-handler.

    <node class="hidden" onclick=toggleVisibilty()"></node>

Or if your not opposed to using jQuery, then you could always use the toggle method, so as to toggle the class that way.

http://api.jquery.com/toggle/

Sign up to request clarification or add additional context in comments.

Comments

0

your code is fine maybe you have syntax error in the same page

function showSearch() {
    document.getElementById("bar_search").style.visibility = "visible";
}
<li class="item" onclick="showSearch()">
    <img id="search" src="https://wiki.ubuntu.com/IconsPage?action=AttachFile&do=get&target=search.png">
</li>
<div id="bar_search" style="visibility: hidden;">
    <img id="search" src="https://i.sstatic.net/X6BXa.png">
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.