Javascript: How to change a button to another button? [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If I wanted to take a button and change it to when clicked to another button using javascript, how would I write this in code?
This is all I have so far but its invalid :/
var change = document.getElementById("fire") === document.getElementById("water");

The HTML:
<button onclick="myFunction()" id="fire">fire</button>
<button id="water" style="visibility:hidden">water</button>
JS:
function myFunction()
{
document.getElementById("fire").style.visibility = 'hidden';
document.getElementById("water").style.visibility = 'visible';
}

you should make two buttons.
Make button A visible initially, button B hidden.
When button A is clicked, hide button A and make button B visible.
This can all be done with CSS. Checkout some jQuery tutorials.

Related

How do I check if an id is 'active'? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have buttons that change color when selected or when "active". Each button holds information to do calculations but when one of the buttons is pressed I need to make a box that holds one of the outputs null. I believe the easiest way to do it would be to place this in my calculations code:
if "button id" is "active"
set value to null
I do not know how to translate that english into javascript.
The ids are what I am giving the CSS ".active" attribute to. Fairly new to the stack overflow thing so if this does not make sense or more information is needed please let me know.
Thanks!
function myfunc(reed) {
if (reed.classList.contains("active")) {
document.getElementById("demon").innerHTML = "Yes I contain .active";
} else {
document.getElementById("demon").innerHTML = "No, sorry not having .active";
}
}
<button class="notactive" onclick="myfunc(this)">Not active</button>
<button class="Iam active" onclick="myfunc(this)">I am active</button>
<span id="demon"></span>

Custom hover popup in HTML/JS/CSS [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
How would one be able to get a popup like the image below on hover of an element? I'm not sure what I should be adding in here apart from that I preferably don't want to use any other libraries apart from jquery. Please tell me if you need any code snippets or any more information!
Let's say you have said element above as a div on your page with an ID of 'cursor'. You can set the display value in your css to 'hidden', so it won't be displayed at first. When you hover over another element, you can trigger functions to display or hide said element:
<div id='hover-element' onmouseover='onMouseOver()' onmouseout='onMouseOut()'></div>
<div id=cursor'</div>
And then inside those functions:
function onMouseOver(element){
document.getElementById('cursor').style.display = 'block';
}
function onMouseOut(element) {
document.getElementById('cursor').style.display = 'none';
}
Try it :)

how to add 2 radio buttons in dialog box in jquery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need call this on button's click event.
I want to perform further actions based on selected radio button.
$("#btnExport").click( )
Check this link. You need to use .dialog if yo want radiobuttons in dialog
http://jsfiddle.net/6FGqN/813/
from what i understood.. i guess you need trigger
try this
$('#yourbutton').click(function(){
$('#radioID').val();//will give you the selected radio's value
$("#btnExport").trigger('click');
});
I am showing you a simply alert on both buttons. Please change as ur need
<input type="radio" id="btnExport1">
<input type="radio" id="btnExport2">
$("#btnExport1").click(function(){
alert('First Button');
})
$("#btnExport2").click(function(){
alert('Second Button');
})
Demo: http://jsfiddle.net/kapil_dev/tq3Bm/

Specific Keymapping JS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm not super familiar with DOM events and such. Currently, what I'd like to do is click on the first object, which is a HTML link with the class name "test", when the user presses 1 on the keyboard and or keypad as well. I'd be using the keydown event since it seems more supported then keypress. How would I go as to doing this?
Using jquery for example:
$(document).on('keydown', function(event) {
if(event.keyCode == 49 // press key 1 on keyboard
|| event.keyCode == 97) // press key 1 on keypad
location.href = $('a.test').attr('href');
});
jsFiddle

Clicking div to toggle checkbox and change css [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've got a site built from many divs. Nearly all div's have the same class (for CSS) and different id. Here's a part of the code:
<div class="box" id="testbox">
<img src=""><br>
Name<br><input name="choice" value="1" id="name" type="checkbox" onchange="onCheckboxChanged(); checkTotal();">
</div>
When I click anywhere in this div I want to check/uncheck it's checkbox (which is hidden so it can't be clicked) and this will toggle onCheckboxChanged() (unlocks more checkboxes) and checkTotal() (adds values from checked checkboxes). Because of that. clicked div's must first check if a checkbox is enabled and then check/uncheck it. Also I want it to change the background of only this div. I would prefer a solution that uses only html/css/js.
What you need is the label element. Use it instead of your div and it will basically do what you need. You can use the disabled property on the checkboxes to enable/disable them.
document.getElementById("testbox").onclick = function(e){
var nameCheck = document.getElementById("name");
nameCheck.checked = !nameCheck.checked;
nameCheck.onchange();
}
jsfiddle - you could do something like this, though I think using a hidden checkbox instead of an attribute on the div could be superfluous.
$('.box').click(function(){
if($(this).find('input[type=checkbox]').is(':checked'))
{
$(this).find('input[type=checkbox]').removeAttr('checked');
/// do other stuffs
}
else
{
$(this).find('input[type=checkbox]').attr('checked','checked');
/// do other stuffs
}
});

Categories