<div id="accordion">
<a role="button" data-parent="#accordion" href="#supercollapse1"> ITEM1 </a>
<div id="supercollapse1">
<a role="button" data-toggle="collapse" href="#subcollapse1" onclick=updateContent()> SUBITEM1 </a>
<div id="subcollapse1">
CONTENT
</div>
</div>
<a role="button" data-parent="#accordion" href="#superollapse2"> ITEM2 </a>
<div id="supercollapse2">
<a role="button" data-toggle="collapse" href="#subcollapse2" onclick=updateContent()> SUBITEM2 </a>
<div id="subcollapse2">
CONTENT
</div>
</div>
</div>
What happens When I open supercollapse1 and then subcollapse1 and then supercollapse2, supercollapse1 closes together with subcollapse1 and supercollapse2 opens. Then I open supercollapse1 - supercollapse2 closes and supercollapse1 together with subcollapse1 opens.
What I want to achieve When supercollapse1 and subcollapse1 are open and I open supercollapse2, supercollapse1 closes together with subcollapse1, so that subcollapse1 does not show when supercollapse1 is opened again.
Motive All subcollapses share one content item which is generated each time they open. So when I already opened subcollapse1, then open subcollapse2 and go back to subcollapse1 - it is already open and content does not get generated.
Tried to be as clear as possible. No offense for the pseudocodish example.
Cheers
If I got you right, closing the level1 accordion(s) should close the level2 accordion(s) that are inside of the level1 accordion(s)
Check out this fiddle: https://jsfiddle.net/459nzh32/
The trick is to listen for the hide event of a level1 accordion, then find its children and close them too, here is an example with jquery:
$('.level1').on('hidden.bs.collapse', function () {
$(this).find('.level2').collapse('hide');
});
Related
Using a VB script (via Excel), I am working on automating some data entry into an IE web page. I have successfully been able to use ".getElementById("WhateverID").Click" in most instances. However, there is a plus sign button that has not been responding to the Click command. Here is what the button ("btnAddAction") looks like:
Add Action
Upon clicking the Add Action button, two new buttons appear ("btnSaveAction" and "btnCancelAction"):
Save Action & Cancel Action
Any suggestions on how to get this Add Action button to respond with this code:
objIE.document.getElementById("btnAddAction").Click
Here is the web inspection code:
<section class="placement-update" id="DecisionUpdate">
<div style="display: block;">
<nav class="navbar navheading blueBar">
<h5 class="heading"> Decision Update</h5>
<div class="ml-auto crd_save">
<img tabindex="-32768" class="pointer" id="btnSaveAction" style="display: inline;" src="/images/save.svg">
</div>
<div class="edit">
<img tabindex="-32768" class="pointer" id="btnAddAction" style="display: none;" src="/images/add.svg">
<img tabindex="-32768" class="pointer" id="btnCancelAction" style="display: inline;" src="/images/cancel.svg">
</div>
</nav>
Created a div component modal that will show when you browse on IE browser. Used v-show to show the modal and change the value when clicking the icon to close the modal.
What is expected?
It will close the modal because of change value in v-show
What is actually happening?
Nothing happens even the value is changing to false
<div class="dashboard-modal" v-show="isModalSearchShow">
<div class="dashboard-modal__modal-mask">
<div class="dashboard-modal__modal-wrapper">
<div class="dashboard-modal__modal-container">
<div class="dashboard-modal__close-container">
<a class="acc-icon g1es-icon-close" #click="isModalSearchShow = false"></a>
</div>
<div class="dashboard-modal__title">
<span>Incompatible Browser</span>
</div>
<div class="dashboard-modal__description">
<span>Works best with Google Chrome and Mozilla Firefox. Please switch to either of these browsers to fully utilize the portal.</span>
</div>
<div class="dashboard-modal__CTA-container">
<a class="btn btn--blue dashboard-modal__CTARefreshList" #click="loadUrl">Got it</a>
</div>
</div>
</div>
</div>
</div>
I have a menu button with a click event in Vue. When the button is clicked, it's supposed to activate the menu itself. This is the parent element which when clicked activates the menu (the toggleMenu function makes menuIsActive true). This part works fine:
<div class="navbar-item has-dropdown #click="toggleMenu">
<div class="navbar-link"></div>
<app-navmenu :class="{'is-active': menuIsActive}"/>
</div>
And this is the app-navmenu component that gets rendered:
<div class="navbar-dropdown" #click.stop>
<div class="container is-fluid">
<div class="column">
<h1 class="title">Title</h1>
<router-link class="navbar-item" :to="route" exact>
<div class="navbar-content">
<p class="has-text-info">info</p>
<small>meta info</small>
</div>
</router-link>
</div>
</div>
</div>
The problem I am running into is that I don't want the menu to disappear when I click on the actual navbar-dropdown div element, hence why I have a #click.stop. However, I do want the menu to disappear when I click on a router-link element, but since I have #click.stop in the navbar-dropdown element, the menu persists. If I don't have a #click.stop event on the navbar-dropdown element, then the menu disappears as soon as the navbar-dropdown element is clicked on, which I don't want.
How can I have the menu persist when clicking on the dropdown body, but also have it disappear when I click on a router-link? I've tried other click methods like .self and .prevent, but those don't seem to do what I need.
I am exactly not sure with your requirement, but following your comment, you can use something like this:
This will even push to the router link:
<router-link class="navbar-item" :to="route" exact
#click.native.prevent="callYourMethod">
This will prevent to go to the router link:
<router-link class="navbar-item" :to="route" exact
#click.native.prevent="callYourMethod" event="">
This is what I ended up doing to fix my issue. First, I moved the click function in the parent to one of its children:
<div class="navbar-item has-dropdown">
<div class="navbar-link" #click="toggleMenu"></div>
<app-navmenu :class="{'is-active': menuIsActive}"/>
</div>
This lets the body of the menu stay active even when I click on the body without having to use a #click.stop. Then in the menu itself, I did this so that links will close the menu:
<div class="navbar-dropdown" #click.stop>
<div class="container is-fluid">
<div class="column">
<h1 class="title">Title</h1>
<div #click="toggleMenu">
<router-link class="navbar-item" :to="route" exact>
<div class="navbar-content">
<p class="has-text-info">info</p>
<small>meta info</small>
</div>
</router-link>
</div>
</div>
</div>
</div>
One strange behavior I noticed is that if I put the #click="toggleMenu" function in the <router-link/> element itself, it doesn't get called on, even if I use .prevent. Hence the need for the div wrapper around the router-link element.
I'd like to target two divs for expand when clicking on a single trigger? Is that possible?
You can simply add all the ids separated by commas in data-target:
<button type="button" data-toggle="collapse" data-target="#demo,#demo1,#demo2">
Hide them all
</button>
Use the same class for both div's and set your data-target according this. Give your div's also the same parent (can also be a class) and set data-parent according this.
<button type="button" data-parent="#wrap" data-toggle="collapse" data-target=".demo">
simple collapsible
</button>
<div id="wrap">
<div class="demo collapse">
test1
</div>
<div class="demo collapse">
test1
</div>
</div>
From the Bootstrap 3 documentation:
The data-target attribute accepts a CSS selector to apply the collapse to.
Therefore you can use a comma-separated list of id's, class selector etc. for the data-target attribute value:
<button class="btn btn-primary"
type="button"
data-toggle="collapse"
data-target="#target1,#target2,#target3"
aria-expanded="false"
aria-controls="target1,target2,target3">
You can see an extensive list of valid CSS selectors on the w3schools website.
If you want to hide one element and show another (like the bootstrap accordion but without a panel) you can add multiple targets but also add the class 'in' to have one element expanded on load!
<div class="collapse text-center clearfix in" id="section1">
<h1>This is section 1</h1>
<p>Are you excited about toggling?</p>
</div>
<div class="collapse text-center clearfix alert-warning" id="section2">
<h1>Boo!!</h1>
<p>This is a new sentence</p>
</div>
<button class="btn btn-block btn-primary" data-toggle="collapse" data-target="#section1,#section2">Toggle</button>
Live demo here
There is a solution in Bootstrap 4:
Bootstrap 4 documentation: Multiple targets
The least you need is:
data-toggle="collapse" data-target=".multi-collapse" for the toggle
button
class="collapse multi-collapse" for each element you need to
toggle
(While multiple ids in data-target indeed don't work).
The data-target answer did not work for me. However you can use JavaScript to do this.
Make your button call some JavaScript like:
$('.collapse-class').collapse('toggle')
See: https://getbootstrap.com/javascript/#via-javascript-3.
Bootstrap 4 uses document.querySelector instead of document.querySelectorAll. If this changes, then everything works.
In Bootstrap 4 using the same class for each respective div seemed to work over using id.
<button type="button" class="btn" data-toggle="collapse" data-target=".collapse-group">
Reveal Items</button>
<div class="row">
<h3>Visible Row div 1</h3>
<div class="collapse-group collapse">
<p>hidden item</p>
</div>
<h3>div 2</h3>
<div class="collapse-group collapse">
<p>hidden item 2</p>
</div>
</div>
I faced the same problem but bootstrap won't let data-toggle="tab" beside data-toggle="collapsed" so my problem was like this.
I have:
<a type="button" class="btn btn-default btn-lg btn-block " href="#ld-tab-pane-eye" aria-expanded="false" aria-controls="ld-tab-pane-eye" role="tab" data-toggle="tab" aria-haspopup="true" aria-expanded="false" style=" border: 0px ;"> </a>
and this was switching tabs:
<button type="button" class="navbar-toggle collapsed nav-trigger style-mobile" data-toggle="collapse" data-target="#main-header-collapse" aria-expanded="false" data-changeclassnames='{ "html": "mobile-nav-activated overflow-hidden" }'>
</button>
But this one closes the modal because the switch tab button was in the modal.
To solve the problem I add id="popout"(to first button) and id="popoutTrigger" (to secend button).
And this script (jQuery):
$( "#popout" ).click(function() {
$( "#popoutTrigger" ).trigger( "click" );
});
When the user clicked the switch button in the modal, after switching modal will close.
This a view of what I've done.
I hope my solution will help.
I'm not able to click on the menu item (Create Defect...) as shown in the figure while testing my webapplication and getting below error
**org.openqa.selenium.ElementNotVisibleException: Cannot click on element**
the below code clicks on the image (hand image) as shown in the figure
driver.findElement(By.xpath("//div[#id='divToolbar']/div/table/tbody/tr/td[2]")).click();
and then the menu opens. Now I would like to click on the menu item.
I'm using below code for this
driver.findElement(By.xpath("html/body/div[10]/div/div/div/div/div/ul/li[1]")).click();
but I got the above mentioned exception
This what I have in the html:
<div class="mmenu" style="display: block; left: 49px; top: 37px;">
<div class="mmenu-content">
<div class="mmenu-border" style="width: 231px;">
<div class="mmenu-inset" style="width: 231px;">
<div class="mmenu-group first-child last-child">
<div class="mmenu-column first-child last-child">
<h3>
<ul>
<li id="liemx360120335239.81635" class="link" menuuid="emx360120335239.81635">
<span class="icon">
<span>Create Defect...</span>
</li>
<li id="liemx172704021676.66638" class="link" menuuid="emx172704021676.66638">
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
Can you please suggest?
have you tried driver.findElement(By.xpath("//span[contains(text(),'Create Defect...']")).click();
I think your problem is that the second menu is invisible, and WebDriver throws ElementNotVisibleException if he operates on a locator which is not visible.
I think you have to keep the first menu open, as the second one to be visible when you try to click it.
I use Actions class.
Try to do following :
new Actions(getWebDriver()).moveToElement(driver.findElement(By.xpath(...))).perform();
and right after try to click the second locator. If you still have problem, try to chain both commands in the same action.