How to create JavaScript counter with plus and minus button left and right like in e-commerce website [closed] - javascript

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 3 days ago.
Improve this question
Can u please help me how to build JavaScript counter function life this (- 0 +) with validation min 0 please help me to solve this with functionality in JavaScript

let counterValue=0;
bindCounterVal()
function increment(){
counterValue++;
bindCounterVal()
}
function decrement(){
counterValue--;
bindCounterVal()
}
function bindCounterVal(){
validateValue()
document.getElementById('counterVal').innerText=counterValue
}
function validateValue(){
if(counterValue>0){
document.getElementById("decrement-btn").disabled = false;
}else{
document.getElementById("decrement-btn").disabled = true;
}
}
<button onclick="increment()">+</button>
<button id="decrement-btn" onclick="decrement()">-</button>
<h1 id='counterVal'></h1>

Related

Find attribute value by searching inner text on a webpage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 months ago.
Improve this question
want to extract the value of value attribute in the code below by it's inner text using javascript.
<label for="played-123">
<input id="played-123" name="players[]" type="checkbox" **value="123"**>
<img class="team" src="teams/abc.png" alt="abc"> Abc Xyz</label>
Here is what I want to extract from above html 123.
Any help will be appreciated.
Thank You.
I did it myself, using:
function get_elements_by_inner(word) {
res = []
elems = [...document.getElementsByTagName('label')];
elems.forEach((elem) => {
if(elem.outerHTML.includes(word)) {
res.push(elem)
}
})
return(res)
}
from #Cybernetic in "How to get element by innerText":
get_elements_by_inner("Abc Xyz")[0].firstElementChild.attributes.value.nodeValue;
This returned my desired value.

How to put for loop inside function for "getElementById"? [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 1 year ago.
Improve this question
I want to put for loop for below function i want loop in "textInput" field so i use same function for different Id's linke textInput1, textInput2,.....
function onButtonClick(){
document.getElementById('textInput').className="show";
}
You can pass id in onclick event and use it like below
function onButtonClick(id){
document.getElementById('textInput'+id).className="show";
}
.show{
display:block
}
.hide{
display:none
}
<input type='button' value='Add' onclick='onButtonClick(1)'>
<div class='show'>show</div>
Or you can also use following but it will run repeatedly when click on button
function onButtonClick(){
for(let i=0;i<10;i++){
document.getElementById('textInput'+i).className="show";
}
}

Hiding a button onClick="" before launching the following method calls [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 8 years ago.
Improve this question
I am not very familiar with inline JS. I have a button such as
<button onClick="return doSomething()"></button>
How do I hide & disable the button before return and doSomething are called? (jQuery available too).
I need the button to be hidden & disabled before the onClick methods are called.
you can do this:
<button onClick="this.disabled = true;this.style.display = 'none';return doSomething()"></button>
Or just do it in your doSomething function:
<button onClick="return doSomething(this)"></button>
function doSomething(obj){
obj.disabled = true;
obj.style.display = 'none'
// other stuff
}
<button onClick="this.style.display = 'none';this.disabled = true;return doSomething()">Button</button>

How to Show/Hide Content From Specific Country [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there any to show content only in pakistan. I have an ad banner of a pakistani Company and i want to show that banner only in pakistan.
You can use a service called Geo-IP API from smart-ip.net:
$(function() {
$.getJSON('http://smart-ip.net/geoip-json?callback=?', function(data) {
if (data.countryCode == 'PK') {
$('#ad_banner').show();
$('body').text('You are from Pakistan');
}else{
$('#ad_banner').hide();
$('body').text('You are from ' + data.countryName);
}
});
});
where PK is the 2-character country identifier of the ISO 3166-1 standard
Fiddle Demo

change the value of parent scope [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 9 years ago.
Improve this question
please help to change the value "allNews" after clicking the button .all_news
http://plnkr.co/edit/xKVpczgVa9wKtIpS95ng?p=preview
as a result of the class .allNews should be added to the block .slide_panel_inner and block height increase to 600px
As you can easily see in the console log (f12), you are getting an error because of your mis-use of ng-class. All you need to do is something like this:
<button ng-click="toggleClass()">Toggle Class</button>
<div ng-class="myDivClass"></div>
in your controller:
$scope.myDivClass= ''; //no class applied
$scope.toggleClass = function() {
$scope.myDivClass = ($scope.myDivClass) ? '' : 'my-class-name-here'; //turn class on or off
};
Live demo here (click).

Categories