jquery code is not working in safari browser - javascript

I have this code in my js file
$.post(storeurl+"/ajax/ajax-action.php", {action: 'removefromsession', id:did, pid:pid}, function(result){
if(result){
obj.closest("span").remove();
}
});
Here is the fiddle.
This code is working in firefox and chrome, but not working in safari, even i did not get any error in console of safari. Is there any solution to make working this code in safari?

Try to wrap the this with $() since .closest() is a jquery function not a plain old javascript's.
$(this).closest("span");
this inside $.post will refer the window object. I think probably this post call might be inside of a click event or something. Cache the this object of the clicked element in a variable then use it inside of success call back.

Related

jQuery onclick placer doing nothing

I have an input on my index page:
<input type="button" name="goReplaceAll" value="Go" id="allReplaceGo" style="cursor:hand;" />
And an onclick call from jquery:
$(document).ready(function() {
$('#allReplaceGo').click(replaceAll);
});
function replaceAll(){ alert('a'); }
When I click the button, nothing happens. When I instead use onclick="replaceAll()" within the HTML, I get an error: Uncaught ReferenceError: replaceAll is not defined
I am unable to figure out a connection between these errors, or any possible cause.
The code is currently live at http://www.texturepacker.net
Edit: Looks like I get two different results in Firefox and Chrome, Chrome does nothing while Firefox alert('a')'s once the page loads. Now I'm just plain confused?
Edit: Seemingly an unrelated syntax error later in my code was breaking the call. Now replaceAll() is called when the dom loads, my question is now why isn't replaceAll() being launched onclick and instead once the dom loads, am I missing something obvious?
Look like a syntax error here...
Line 196 in you script file says
$(this).("src",tmpSrc);
It is supposed to be
$(this).attr("src",tmpSrc);
Fix that and it should be all fine..
Also on line 7
$('#allReplaceGo').live("click",replaceAll());
is supposed to be
$('#allReplaceGo').live("click",replaceAll);
Also as of version 1.7 .live() is deprecated. try using .on() instead
That happens, probably, because the function replaceAll is outside the jQuery scope.
Try to put her inside the $(document).ready scope.
Your code should look like
$(document).ready(function() {
$('#allReplaceGo').click(function(){
replaceAll()
});
});
function replaceAll(){ alert('a'); }

Why is my onclick event not registered in Firefox?

I have a list item with an onclick event. It runs in Chrome and Internet Explorer, but not Firefox. Any suggestions?
<li onclick="alert('test');">test test<br></li>
This works fine for me in Firefox.
Check this:
JavaScript is enabled in your browser.
Try adding a return false; statement in your tag.
Or a function like this:
function test() {
//your code here
return false;
}
Or use this:
Link
or this
Link
I was trying to minimize my html code to send a complete code to simulate the error as Boris Zbarsky requested. Then I found my mistake.
I was using marquee tag which has been deprecated. Now I am going to use jQuery instead of it.
thx
In Firefox, the event object is not global. You have to access it within your script tags not in html.
onclick works likes this
<li id="alert">test<br></li>
<script>
document.getElementById("alert").addEventListener("click", function( event ) {
alert('test');
}, false);
</script>
Attributes can be ignored by Firefox when it is served invalid HTML, use
https://validator.w3.org/
to clean up the HTML.

Internet Explorer 7 + alert() doesn't work

Can some of you please tell me why a simple alert() isn't working using jQuery 1.4 in Internet Explorer 7, when it's working in all other browsers? It's been driving me crazy now for the last half an hour..!
$(document).ready(function(){
alert("wtf?");
})
This simple example doesn't show an alert in IE7. See for yourself at http://jsfiddle.net/8HQdp/.
Ensure your console doesn't show any errors and correct them if there are any.
Be sure you didn't disable browser prompts on IE
Try using window.alert() - it's possible (though improbable) that another alert() is conflicting with window's.
If you have console support, try console.log(alert); and see what it says. It should be something like:
function alert() {
[native code]
}
I'm using IE8 but with IE7 mode, the alert on http://jsfiddle.net/8HQdp/ still triggers.
Try changing $ to jQuery and host your own jquery.js.
And also try console.log('wtf') before alert so u know whether it's alert or document.ready is broken.
It works in IE 7 mode in IE 8 form me. Takes a while but it does trigger.
I noticed that there is a semi colon missing from the ready function. should be...
$(document).ready(function(){
}); //missing semicolon here
Also, try using the shortcut for the DOM ready function...
$(function(){
// code here
});
Try using window not document.

Strange Issue in Internet Explorer using Flex

Im using a flex plugin with a methode:
ExternalInterface.call("initialize_width");
This calls a jQuery Function witch initializes the width of the window:
function initialize_width(){
$("#nav_content").css("width",900);
}
It works perfectly on all the browsers expect Internet Explorer...
It says: "'null' is null or not an object", and points to:
try { document.getElementById("").SetReturnValue(__flash__toXML(initialize_width()) ); }
catch (e) { document.getElementById("").SetReturnValue("<undefined/>"); }
I've no idea what the problem should be as the place where the debugger points to is pointing to automatically created code..
Any help?
Thanks Markus
Why are you using document.getElementById("")?
This will return null every time, and you're trying to then call a method on null.
If that's just a code error, then make sure the ID you're getting the element of is the only element on the page with that ID, as there may be a conflict there.
Additionally, you can use
$("#nav_content").width(900);
instead of your css call (though I can't see that fixing your problem).

Click event not worked in Firefox

I am using a jquery click function:
Button code
<input type="button" id="myButtton">
Jquery code
$(document).ready(function () {
$("#myButtton").click(function () {
alert("Mybutton");
});
});
This code works in Internet Explorer but does not work in Firefox.
What am I doing wrong?
In the code:
$(document).ready(function(){
$("#myButtton").click(function(){
alert("Mybutton");
});
I believe it's missing another closing brace:
$(document).ready(function(){
$("#myButtton").click(function(){
alert("Mybutton");
});
});
My best guess is that you have other input with the same ID? Try using classes instead, or use jQuery's CSS selector like $('input[type=button]') instead.
I'd also recommend installing FireBug plugin for FireFox if you haven't done so already (http://www.getfirebug.com/). It'll help you debug JavaScript issues like this, and a whole lot more.
Are you sure that element has an id attribute? Or does it have only a name attribute with a value of "myButton". In order to work cross browser the id attribute is mandatory, whereas name is optional (only IE and Opera AFAIK).
N.B.: My answer may seem idiot, but it was not the original poster that added the code example in the question (view edit history).

Categories