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
First I echoed a button using PHP with value='pause'.Then I wrote a simple if statement in jquery
$(":button").click(function(){
if($(this).attr("value") == "pause"){
alert($(this).attr("value"));
$(this).attr("value") = "play";
}else{
alert($(this).attr("value"));
$(this).attr("value") = "pause";
}
});
But the result is always alert("pause");
What I am trying to do is if I click the button with value='pause', i want to execute an ajax request and change its value to 'play' so that on the next click it will execute another bit of code and set its value back to pause.
This code is meaningless:
$(this).attr("value") = "pause";
That probably generated errors that you're not paying attention to. When working with JavaScript code, always have your console open.
What you want is:
$(this).attr("value", "pause");
Even better, as IFun points out:
$(this).val("pause");
Make sure to consult the attr() documentation.
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 5 years ago.
Improve this question
I'm trying to add two actions in one button click, one handle form post another to show alert , the one for post works but the one to show alert doesn't .and when i try another action inside this button click does not work too
$('plot_marker').click(function () {
$.post('/searched/', $('mapform').serialize(), function (data) {
},
'json' // I expect a JSON response
);
alert("Hello!");
});
Unless you're using Web Components or some other framework, you almost certainly meant $('#plot_marker') or $('.plot_marker').
In your sample code you have used the is a tag selector which is a valid query selector used for selecting tags by name, but that was likely not your original intent.
In the below code, unless 'plot_marker' is a tag name, it should either be '#plot_marker' or '.plot_marker' depending on whether it is an id or a class.
$('plot_marker').click(function () {
$.post('/searched/', $('mapform').serialize(), function (data) {
},
'json' // I expect a JSON response
);
alert("Hello!");
});
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 7 years ago.
Improve this question
I am building a lightbox and am running into an issue where the following fadeIn function is firing at the same time as the fadeOut instead of afterwards.
Why is updateImage.call(this) firing at the same time as the fadeOut? Should it not fire afterwards considering it is placed as a callback?
Full code snippet
function updateImage() {
activeImage = overlayImagesBox.find('.' + this.className);
activeImage.fadeIn('slow').addClass('active-image');
}
imageLinks.on('click', function (e) {
e.preventDefault();
if (!activeImage) {
updateImage.call(this);
} else {
activeImage.removeClass('active-image').fadeOut('slow', updateImage.call(this));
activeImage = null;
}
});
As #blex mentioned in the comments the correct answer is simply passing the function as a callback instead of executing it. Thank you for the help everyone.
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 am trying to accomplish a 'simple' jQuery effect.
When an user loads their dashboard, and they have a specific id (#) in the url, the dashboard should load the content assigned to that specific id.
Here is what I have so far:
var pathname = window.location.hash.substr(1);
if(pathname = loadextra){
$('.loadextra').addClass('active');
$('.load-fixed').removeClass('active');
$('.fixed-ads').hide();
$('#loader').show().html('<div class="typing_loader_holder"><div class="typing_loader"></div></div>');
setTimeout(
function()
{
$('#loader').hide();
$('.extra-ads').show();
}, 2000);
}elseif(pathname = loadfixed){
$(this).addClass('active');
$('.load-extra').removeClass('active');
$('.extra-ads').hide();
$('#loader').show().html('<div class="typing_loader_holder"><div class="typing_loader"></div></div>');
setTimeout(
function()
{
$('#loader').hide();
$('.fixed-ads').show();
}, 2000);
}else{
//do nothing
}
So, imagine an user goes to: http://website.com/user#loadextra then the code inside if(pathname = loadextra){} should be fired off - same goes for #loadfixed
Although, as it is now, if you just goes to http://website.com/user, then if(pathname = loadextra){} is fired of.
Why doesn't the if/elseif/else statement work in my code?
You have make three mistakes:
1) Replace '=' with '==' in if & elseif
2) Replace 'elseif' with 'else if'
3)Replace $(this).addClass('active'); with $('.loadfixed').addClass('active');
Try this:
if(pathname == loadextra)
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 a list of li tags in an unordered list and each li has an attribute called data-clicked=false. this if... else if... statement will test to see if data-clicked==true/false and then give an alert with the value of the attribute. The problem is that this is always alerting "true" when it should be "false" since by default at the start they are all set to false.
$("ul").click(function(event) {
if ($(event.target).data("clicked"==true)) {
alert("true")
}
else if ($(event.target).data("clicked"==false)) {
alert("false")
}
});
basically all I want to know is how I can test to see if the data-clicked attribute is true or false.
your condition
if ($(event.target).data("clicked"==true)) {
wont work. It should be
if ($(event.target).data("clicked")==true) {
and same would be the case for the else if part
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
So, I have the script below and it successfully checks the values of the inputs when I click on a div with onclick="checkInputs()" inside.
But when I click the div again, it doesn't run the code. would I have to put return false; after it?
function checkInputs() {
if (document.getElementById("emailAdressInput").Value === "ADRESSHERE" && document.getElementById("passwordInput").Value === "PassHere")
{
document.getElementById("notifier").innerHTML = "Login Successful!";
}
else
{
document.getElementById("notifier").innerHTML = "Login Unsuccessful.";
}
}
To get the value of element you should use value not Value
document.getElementById("passwordInput").value
instead of
document.getElementById("passwordInput").Value;
UPDATE
Here is your working DEMO
The strict operator === checks for type also, If you put passHere instead of PassHere it reurns false.