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 make a button that once click will show "Hello World", But it does not work. I don't know where I made mistakes.
This is button an div.
<button type="button" onclick="myFunction():"> Click me to see the result</button>
<div id="demo"></div>
This is my script.
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
The colon should be removed from "myFunction()".
Related
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 1 year ago.
Improve this question
How can I write a function within the onclick event of a button
What I want to do is something similar to this:
<button onclick="(function(){
console.log('some code here')
})">My button</button>
You'll need to invoke the function:
<button onclick="(function(){
console.log('click')
})()">My button</button>
<button>
onclick="(function(){console.log('click')})()"
>Button
</button>
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 am trying to change the onclick value of a Button via Javascript. But in the moment I change its value, the function is executed directly.
document.getElementById('Send').disabled = false;
document.getElementById('Send').addEventListener("click", window.location.href = 'http://www.google.com');
Second parameter must be a function! Try:
document.getElementById('Send')
.addEventListener("click",
function(){window.location.href = 'http://www.google.com'});
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 9 years ago.
Improve this question
I'm trying to change the body content when I resize the windows, but after 2 hours searching and trying, I get nothing.
This is my last jQuery code:
$(window).resize(function(){
if($(window).width<=320){
changeHTML();
}
});
var changeHTML=function(){
alert("wow");
//$('body').load('../index2.html');
}
The "index2.html" is something like this:
<div>
A lot of stuff
</div>
$(window).width is incorrect, as width() is a method. Use $(window).width() instead.
See working jsFiddle demo
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 9 years ago.
Improve this question
I am writing a code for quiz,whenever one option is selected by the user from out of four option,i want to alert. I have something similar to my code here:-
<label class="alert optiona">
</lablel>
I am having value
data.correct="optiona";
I need to send pass the value in javascript.When i am passing following syntax , it doesnt send the value of data.correct.
$(".alert "+data.correct).attr("class", "alert alert-"+ data.mode);
You're missing the dot in the selector and you have a space which means that the second class applies to a descendant of the .alert element.
Change
$(".alert "+data.correct)
to
$(".alert."+data.correct)
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 3 years ago.
Improve this question
I am trying to manipulate elements outside of iframe by setting JS inside of my iframe
The style.backgroundColor code works but not innerHtml
I have
<script type="text/javascript">
//get main document element.
var ititle= parent.document.getElementById('MainTitle');
//works
ititle.style.backgroundColor = "#FFCC00";
//doesn't work
ititle.innerHtml='test html';
</script>
The above script is inside my iframe
Are there any reasons why? Thanks a lot.
Because JavaScript is CaseSensitive, and it's innerHTML (all uppers):
ititle.innerHtml='test html';
//should be
ititle.innerHTML='test html';