Javscript code
/* ---------- Submenu ---------- */
$('.dropmenu').click(function(e){
e.preventDefault();
$(this).parent().find('ul').slideDown();
});
webpage code
<li>
<a class="dropmenu" href=""><i class="fa-icon-folder-close-alt"></i><span class="hidden-tablet"> Databases</span></a>
<ul>
<li><a class="submenu" href="/rinks"><i class="fa-icon-file-alt"></i><span class="hidden-tablet"> Rinks</span></a></li>
<li><a class="submenu" href=""><i class="fa-icon-file-alt"></i><span class="hidden-tablet"> Users</span></a></li>
</ul>
</li>
So I have this piece of code that triggers a dropdown menu to expand when the element "a class="dropmenu" href=" is clicked.
I am trying to trigger this event when another element has a value set to it but I can't figure out how to call the slidedown function from the console.
I dont want to trigger with the click() command. I want to be able to execute $(this).parent().find('ul').slideDown(); but from the console side. That way I can call other functions like slideToggle. Basically I want to be able to rung the below code to trigger the slidedown, not the click event, I would remove the click event.
$(document).ready(function(){
//Message functions
if (document.getElementbyId("testing").value == "BestGame"){
$(this).parent().find('ul').slideDown();
}
You can declare a method to be called in the click event
$('.dropmenu').click(function (e) {
var el = this;
e.preventDefault();
toggleMenu(el);
};
var toggleMenu = function (el) {
$(el).parent().find('ul').slideDown();
}
So from the console all you would have to do is
toggleMenu('.dropmenu')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.