I have added a dynamic class called hello to the last question from the form. I am trying to traverse through the DOM to get the grandparent element .question-popup but for some reason it does not work. Ideally once I get to question-popup from hello I want to be able to get to the class="step-through-btn o-wrapper" to change the text of the button the "NEXT STEP".
$(".js-cme-next-question-button").click(function(){
$(".js-test-questions-wrap .c-cme-test:last .o-overlay__question").addClass("hello");
console.log($(".hello").closest(".question-popup"));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="question-popup">
<div class="test-questions">
<div class="count">counter</div>
<div class="h6 u-text-grey o-overlay__question1 hello"> **hello added dynamically**
<div class="h6 u-text-grey o-overlay__question2">
<div class="h6 u-text-grey o-overlay__question3">
</div>
</div>
<div class="step-through-btn o-wrapper">
Next question
</div>
You can do so with plain javascript. But be warned your html code isn't well structured. But mine is so:
var hello = document.querySelector(".hello");
var parent = hello.closest(".question-popup");
var sibling = parent.nextElementSibling;
var button = sibling.querySelector(".c-button")
button.innerText = "NEXT STEP";
<div class="question-popup">
<div class="test-questions">
<div class="count">counter</div>
<div class="h6 u-text-grey o-overlay__question1 hello"> **hello added dynamically**</div>
<div class="h6 u-text-grey o-overlay__question2"></div>
<div class="h6 u-text-grey o-overlay__question3"></div>
</div>
</div>
<div class="step-through-btn o-wrapper">
Next question
</div>
Related
Im trying to click on the first element that look like this:
<div>
<div class="report-name" data-qa="x1x">
<div tabindex="0" class="af-core keyboard-navigation-element gray-link"><a class="af-core link-with-arrow right " target="_blank">boxes</a></div>
</div>
<div class="report-name" data-qa="x2x">
<div tabindex="0" class="af-core keyboard-navigation-element gray-link"><a class="af-core link-with-arrow right " target="_blank">bags</a> </div>
</div>
</div>
i tried this 2 lines of code:
await page.click('div[data-qa="x1x"]');
await page.$x("//a[contains(text(), 'boxes')]");
but I cannot click on it.
I'm trying to make an FAQ page using an accordion. In some of the answers I tried to make a clickable link, that will direct you to another question (I don't want the page to refresh).
With what I have now, the opened question (containing the link) will close the accordion after clicking, and open the desired accordion. The only thing missing is that the page will not scroll to the new question.
What I've got:
function openQuestion(q) {
jQuery('.accordion-toggle').removeClass('active');
jQuery('.accordion-container').fadeOut(500);
var accordions = jQuery('.accordion-toggle');
var accordion = accordions[q - 1];
jQuery(accordion).addClass('active');
jQuery(accordion).next('.accordion-container').slideToggle(500);
}
I assume the next jquery line would contain something with scrollIntoView. But no succes yet.
This is what I use in HTML
text
<div class="entry">
<h3>FAQ</h3>
<p>...</p>
<div class="clear"></div>
<div class="accordion wrapper">
<h3 class="accordion toggle active">
...
</h3>
<div class="accordion-container" style="display: block;">
<div class="content-block">
<span style="font-weight: 400;">...</span>
</div>
</div>
<!-- end accordion container -->
<h3 class="accordion toggle">...</h3>
<div class="accordion-container" style="display: none;">...</div>
<!-- end accordion container -->
</div>
</div>
I am trying to find the parent of the span element with label First Name and go up the DOM until i get to the input element with class "mat-input-element"
I have attempted with the following xpath, but did not get the result i needed:
//div/div/span[contains(.,'First Name')]/parent::div[#class='add-users']/lib-text-input-v3/div/mat-form-field/div/div/div[1]/input
Any help would be appreciated. Thanks!
You can try with the below xpath.
//span[normalize-space(.)='First Name']/ancestor::div[#class='input-v3']//input[#class='mat-input-element']
Sample HTML: From jsfiddle
<html><head></head><body>
<div class="add-users">
<lib-text-input-v3 errortext="”Error" a="" valid="" first="" name”="">
<div class="input-v3">
<mat-form-field class="mat-form-field">
<div class="mat-form-field-wrapper">
<div class="mat-form-field-flex">
<div class="mat-form-field-infix">
<input class="mat-input-element" type="text">
<span class="mat-form-field-label-wrapper">
</span>
</div>
</div>
<div class="mat-form-field-underline>
<span class=" mat-form-field-ripple"="">
</div>
<div class="mat-form-field-subscript-wrapper">
<div class="mat-form-field-hint-wrapper">
<div class="mat-form-field-hint-spacer">
</div>
</div>
</div>
</div>. //closes mat-form-field-wrapper class
</mat-form-field>
<div class="input-v3__label"> // same level as input-v3 class
<div class="input-v3__label--text">
<span class="ng-tns-c11-01">First Name
</span>
</div>
</div>
</div> // closes input-v3 class
</lib-text-input-v3>
<lib-text-input-v3>…..
</lib-text-input-v3></div></body></html>
I just want to add a tooltip to the element which is clicked.
Tooltip is added to all repeat elements when clicked. Please help me.
<div ng-repeat="item in listOfMenu" class="repeat_container">
<div ng-repeat="menu in item" class="repeat_block" ng-click="getTool(menu,menu.pricelist.length)" >
<div class="shadow img_cont">
<img src="{{menu.itemimage}}" class="item_img">
<div ng-repeat="innerItem in menu.pricelist | limitTo:1">
{{innerItem.itemprice}}
</div>
</div>
<div>
{{menu.menuitemname}}
</div>
<div ng-repeat="menu in addToCart" class="add_circle" ng-show="circle">
{{menu.quantity}}
</div>
</div>
</div>
Change the div in:
<div ng-repeat="menu in item" class="repeat_block" ng-click="getTool(menu,menu.pricelist.length)" ng-class="{'clicked': menu.clicked}">
In getTool method
menu.clicked = true;
but you should put clicked:false to all others menu in items
I've got this code in the jsp (sized down a bit):
<div class="popup default" ng-app="interview" ng-init="employeeId = '${employee.id}'; findTimelineEntries(); getAddInterviewRights(); getEditInterviewRights();" ng-controller="TimelineCtrl">
<div class="box-wrapper edit" ng-show="hasAddInterviewRights">
<div class="box">
<div class="pointer"></div>
<div class="box-content">
<div class="icon close" ></div>
<div class="form-item">
<!-- cut -->
</div>
</div>
<div class="form" id="convo">
<div class="form-item">
<!-- cut -->
</div>
<div class="form-break"></div>
<div class="form-item">
<div class="label">
<div class="fi-content">
Currently open goals
</div>
</div>
<div class="value">
<div class="editable" ng-repeat="goal in interviewForm.goals" ng-click="openEditable($event.target)">
<div class="icon edit"></div>
<div class="icon close" ng-click="closeEditable($event.target)"></div>
{{goal.shortDescription}}
<div class="ed-content">
<div class="form-item">
<div class="label">
<div class="fi-content">
Deadline
</div>
</div>
<div class="value">
<input type="text" ng-model="goal.dueDate" ui-date="dateOptions" size="15" />
</div>
</div>
<div class="form-item">
<div class="label">
<div class="fi-content">
Status
</div>
</div>
<div class="value select">
<select ng-model="goal.status" ng-options="code as description for (code, description) in goalStatusses"></select>
</div>
</div>
<div class="form-item">
<div class="label">
<div class="fi-content">
Comment
</div>
</div>
<div class="value">
<div class="fi-content">
<table class="plain">
<tr ng-repeat="progress in goal.progresses">
<td>{{progress.progressDate | date: 'dd-MM-yyyy'}}</td>
<td>{{progress.progressReport}}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="editable">
<div class="icon add"></div>
<div class="icon close" ng-click="closeEditable($event.target)"></div>
Add a new goal
And it works in Firefox (20.0.1) just like it should: It shows 2 current goals and the option to add a new goal. But somehow the same jsp doesn't work that well in Chrome (27) as it just shows the option to add a new goal
When looking into the HTML with the Developer Tools I see that the ng-repeat is commented out by Chrome, but why would it do that??
I googled on ng-repeat getting commented out, but the answer there was that the div using the ng-repeat was not inside the div with the ng-controller, but that's certainly not the case with my code
The HTML taken from the Developer Tools:
<div class="value">
<!-- ngRepeat: goal in interviewForm.goals -->
<div class="editable">
<div class=icon add"></div>
<div class=icon close" ng-click="closeEditable($event.target)" style="dispay:none;"></div>
Add new goal
I've checked other browsers and it doesn't work in Safari (5.1) either and also doesn't work in IE8 although a colleague says it does work in his IE9
Well, I finally found what was going wrong and it actually was a
$('.select .option').click(function() {
var choice = $(this).text();
etc.
that had to be changed into
$(".select #itemAddSelector").change(function(){
var selectedOption = $(this).children(":selected");
var choice = $(selectedOption).text();
etc.
As the function that retrieves the goals from the controller was never called in Chrome, because Chrome doesn't process a jQuery click event on an option (Click event on select option element in chrome).
So it just commented in the HTML about ng-repeat saying it had tried to iterate over the goal objects, but there were no objects present ... pfff, I've been looking in the wrong direction for too long.