jquery search problem. all forms are showing -
all forms showing.. want #google-search
active on page load. thank you
$(".header-search-input").keyup(function() { $(".header-search-input").val($(this).val()); }); var $searchbylinks = $("#search-by > a"); $searchbylinks.click(function() { var $el = $(this) $(".header-search-form").hide(); $($el.attr("href")).show(); $searchbylinks.removeclass("cur-search"); $el.addclass("cur-search"); return false; }); <div id="search-by"> <a class="cur-search" href="#google-search">google</a> <a href="#image-search">images</a> <a href="#youtube-search">youtube</a> <a href="#maps-search">maps</a> </div>
i think should work hide links aren't represented class-name 'cur-search':
$(document).ready( function(){ $('#search-by a:not(".cur-search")').hide(); });
js fiddle demo: http://jsfiddle.net/davidthomas/azugw/.
or, alternatively, if don't know specific class of element not-hide:
$(document).ready( function(){ $('#search-by a').not(':contains(google)').hide(); });
js fiddle demo: http://jsfiddle.net/davidthomas/azugw/1/.
assuming it's first form element want show, can use:
$('form:gt(0)').hide();
which uses gt()
, suspect obvious, hide form
elements index greater 0.
js fiddle demo at: http://jsfiddle.net/davidthomas/gnbks/3/.
or, alternatively, use this:
$('form').each( function(){ var curform = $('.cur-search').attr('href').substr(1); if (this.id != curform) { $(this).hide(); } });
which bit messy, finds form
want show (based on link cur-search
class), , iterates through forms work out show , hides others.
js fiddle demo at: http://jsfiddle.net/davidthomas/gnbks/4/.
Comments
Post a Comment