Query or php issue? My code for jquery showme toggle isn't working (code mentioned in previous post) -
i excited read post using toggle click , show , click , hide text (how alter toggle text on show hide using javascript), couldn't code work. when click on underlined hyperlink no text shows up.
in function.php: add_action('wp_enqueue_scripts', 'my_scripts_method'); function my_scripts_method() { wp_enqueue_script('showme',get_template_directory_uri() . '/admin/wp- includes/js/jquery/showme.js'); } in ftp drive: jquery(document).ready(function($) { $(function showme(id)) { var divid = $(document.getelementbyid(id)); $(if (divid.style.display == 'block') divid.style.display = 'none'); $(else divid.style.display = 'block'); } array('jquery') ); } }); html in page: <a onclick="showme('list');" href="#"><h3>air barrier association of america (abaa) certification training</h3> </a> <div class="showme" style="display: none;">this widget</div> <div class="showme" style="display: none;">this widget</div> <div class="showme" style="display: none;">self adhered & fluid applied installer training</div>
the script doesn't work because have syntax errors in it.
you have misunderstood how utilize jquery. it's library utilize regular javascript code, don't utilize putting $(...)
around every line in javascript code.
let's take step step. stripping of code wrong give you:
function showme(id) { var divid = document.getelementbyid(id); if (divid.style.display == 'block') { divid.style.display = 'none'; } else { divid.style.display = 'block'; } }
using jquery in code accomplish same this:
function showme(id) { var divid = $('#' + id); if (divid.is(':visible')) { divid.hide(); } else { divid.show(); } }
you can utilize toggle
method same:
function showme(id) { $('#' + id).toggle(); }
of course of study have phone call showme
in html code, not showme
, javascript case sensetive, , have add together id list
element want toggle.
if intended toggle elements class showme
, be:
function showme(classname) { $('.' + classname).toggle(); }
and phone call showme('showme')
instead of showme('list')
.
you can bind event in javascript code instead of having inline onclick
attribute. utilize ready
event this, event bound after page ready, link exists:
$(document).ready(function(){ $('a').click(function(){ showme('list'); }); });
jquery toggle
No comments:
Post a Comment