php - How to switch images with jQuery using .load()? -


I am creating a button for the WordPress plugin when you click on it, then use it for later use the computer But the cookie should be changed and saved on The cookie will be saved, and if I am making the page fresh, the square is becoming a triangle

My problem is, when I click on the user on it, it is refreshing to want #MyDiv upate for the picture Are there. -> MyCookie -> checks the cookie -> shows the correct picture (triangle or square.png). I have tried to search around for a few days, but the correct answer can not be found. I've tried. HTML () as well, and it updates the picture, but I can not click on it before the page refreshes. I hope you can and help me.

Cheers Mathias

  & lt; Div id = "MyDiv" & gt; & Lt ;? Php if (isset ($ _cookie ["MyCookie"]) and $ _COOKIE ['MyCookie'] == 1) {$ file = triangle.png $ id = TR; } And {$ file = square.png; $ Id = sq; }? & Gt; & Lt; A href = "#" id = "& lt ;? php echo" $ id "& gt;" & Gt; & Lt; Img src = "& lt ;? php echo" $ file "& gt ;?" & Gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; Script & gt; Click (function (avit) {document.cookie = "MyCookie = 0"; $ ('# MyDiv'). Load (local.href + '#MyDiv') evt.preventDefault (); ("." ) Click (function (evt)}, jQuery {document.cookie = "MyCookie = 1"; $ ('# MyDiv') load (local.href + '# MyDiv'). Evt.preventDefault (); });}) & Lt; / Script & gt;  

An easy way to get cookies in jQuery.

Here's a pretty simple example code:

HTML:

   & Lt; Input type = "button" value = "load image" id = "load-image" /> & Lt; / Div & gt; JQuery / <> 

jQuery:

  / ** Until jQuery is ready * / jQuery (document) .ready (function () {JQuery ("# Load-picture") (function () {var image = jQuery (". Image"); var cookie_content = jQuery.cookie ("MyCookie"); / ** Change image accordingly * / if ( "Id", "square");} and {jQuery (image) .attr ("Src", "triangle page"). Attr ("id", "triangle");} return false;});});  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -