javascript target text but not child element [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Ive got the following html:
<span class="woocommerce-order-overview__total total">
Gesamt: <strong><span class="woocommerce-Price-amount amount">0,85<span class="woocommerce-Price-currencySymbol">€</span></span></strong>
</span>
My wanted output is the value 0,85 but without the currency symbol. How do I have to modify this Javascript?
function(){ var capturedText = document.querySelector(".woocommerce-order-overview__total span.woocommerce-Price-amount").innerText.match(/^(.*).{1}/i)[1].trim(); return capturedText; }

You can use childNodes to get that text node:
var capturedText = document.querySelector(".woocommerce-order-overview__total span.woocommerce-Price-amount").childNodes[0].textContent;
console.log(capturedText);
<span class="woocommerce-order-overview__total total">
Gesamt: <strong><span class="woocommerce-Price-amount amount">0,85<span class="woocommerce-Price-currencySymbol">€</span></span></strong>
</span>

Related

How do I get the value of a child div [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Good day,
I would like to ask how I can get the value from price. Neither of them has a unique id so it makes things hard for a noob like me. Any suggestions? Thanks.
<div class="modal">
<span class="name">$</span>
<span class="price">0.04</span>
<hr style="background: linear-gradient(to right, #ffc82d , #ffff73);">
<div class="weapon" style="background-image: url('assets/img/free_case_item.png');"></div>
</div>
You can do it with pure JavaScript using DOM manipulation.
Assuming you only have one element with the price class: document.getElementsByClassName("price").item(0).innerText.
Ideally you would give it an ID (e.g. price): document.getElementById("price").innerText
You can try with document.querySelector:
var price = document.querySelector("div.modal span.price").innerText
This matches the first <span class="price"> inside <div class="modal">.

Why isn't this working? Javascript, text inputs' values and using them in an if statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I think I'm missing something stupidly simple but can't figure out why this isn't working. I'm trying to use 4 values from 4 text inputs and activate an alert when the values = the string value stated.
<div id="AnswersFriends">
<input type="text" align="center" id="TextFriend1" oninput="checkchange">
<input type="text" align="center" id="TextFriend2" oninput="checkchange">
<input type="text" align="center" id="TextFriend3" oninput="checkchange">
<input type="text" align="center" id="TextFriend4" oninput="checkchange">
</div>
<script type="text/javascript">
function checkchange(){
var Ans1 = document.getElementsByID('TextFriend1').value;
var Ans2 = document.getElementsByID('TextFriend2').value;
var Ans3 = document.getElementsByID('TextFriend3').value;
var Ans4 = document.getElementsByID('TextFriend4').value;
if(Ans1=="Joe" && Ans2=="Joe" && Ans3=="Hugo" && Ans4=="Nathan") {
alert("WellDone");
}
}
</script>
change this:
oninput="checkchange"
to this for all the input tags:
oninput="checkchange()"
Also, change this:
document.getElementsByID('TextFriend1').value;
to this:
document.getElementById('TextFriend1').value;
then, do the same for the other getElementById() methods.
To call a function you have to put () after its name
There is no function called getElementsByID, it is getElementById (with a singular element and a lower-case d on the end).

Using a single button to show and hide text [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I don't know if this will be a duplicate, but I've tried multiple scripts (not just in jQuery, but also in Javascript) to try to get the job done. Here's the HTML:
<p id="text">
I will disappear!
</p>
<button id="togglebutton">
Go!
</button>
And jQuery:
$('#togglebutton').click(function() {
$('text').toggle('slow');
});
Click me to try the Fiddle
I hope you may be able to find a solution. Thanks :D
use #test instead of test to select an id attribute in jquery
$('#togglebutton').click(function() {
$('#text').toggle('slow');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="text">
I will disappear!
</p>
<button id="togglebutton">
Go!
</button>
Because you're selecting an ID, $('text') should be $('#text')
$('#togglebutton').click(function() {
$('#text').toggle('slow');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="text">
I will disappear!
</p>
<button id="togglebutton">
Go!
</button>
You're missing the # sign for the text attribute.
$('#togglebutton').click(function() {
$('#text').toggle('slow');
});

Div tag content not showing on click [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to display the data of a div tag on a href click, the id is dynamically made. But the div tag is not responding. The sequence of the code is as below. The file is the .tpl file.
function editPickUpAddress(divId)
{
("#pickupAddressForm_"+divId).show();
}
<a href style="float:right;margin-top:-20px;margin-right:100px;" onclick="editPickUpAddress({$item.profile_id});">Edit</a>
<div id="pickupAddressForm_{$item.profile_id}" style="display:none">
//some content to display
</div>
After cleaning up your snippet and including jQuery, the code works as intended. Also note the href="#" which prevents the anchor tag from navigating to another page.
function editPickUpAddress(divId) {
$("#pickupAddressForm_" + divId).show();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Edit
<div id="pickupAddressForm_1" style="display:none">
//some content to display
</div>

insert text into span class using jquery [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have following html structure
<a id="myBtn" class="ui-link">
<span class="number"> </span>
<span class="button "> </span>
</a>
I want dynamically to insert some content into <span class="number">
var content = 99;
$('number').html(content);
but nothing change.
So what I need to do insert value into span that resulted node looks like this
<span class="number">99</span>
You are not using . to get class selector. Use $('.number') instead of $('number')
$('.number').html(content);
OR
$('.number').text(content);
insert text using class
var content = 99;
$('.number').html(content);
Try this:
$('.number').html(content);
You are referring to a wrong element. You can also do this:
$('.number').text(content);

Categories