EllisLab text mark
Advanced Search
     
Jquery manipulation with previously jquery loaded data
Posted: 06 October 2012 12:58 PM   [ Ignore ]
Joined: 2012-06-20
6 posts

Hi all,
I’m working in uploadify integration on CI and have trouble, when I upload some photos, then those photos with jquery display on the page ...and I append to each of photo ability to delete (without reloading page), but this is not working - I build simple example what is wrong and what I need:

<body>
<
h1>Test jQuery</h1>
[removed]
$(function(){
$("#img1").click(function(){
$("#img1").hide();
$(
"#target").replaceWith('<p id="target2">Hello</p>'+'<img id="test2" src="cross.png" alt="cross.png, 655B" title="Cross" border="0" height="16" width="16">');
});

$(
"#test2").click(function(){
alert(
"OK");
});

});
[removed]
<img id="img1" src="cross.png" alt="cross.png, 655B" title="Cross" border="0" height="16" width="16">
<
p id="target">This is a test</p>


</
body

So I need, after jQuery loads results, that this results pass another jquery action (and ajax).

Thanks for help.

 
Posted: 06 October 2012 08:25 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
454 posts

The issue you are having is because the image html is generated code, and so not bound to the jquery code

The easiest fix is to use .live(‘click’, function(){...}) instead (or .on() is recommended now, but it isn’t 100% the same)

http://api.jquery.com/live/

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 06 October 2012 09:50 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-06-20
6 posts

Wow!
very thanks this is exactly what I need!

Once again very thanks.

 
Posted: 07 October 2012 12:34 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1415 posts
jmadsen - 06 October 2012 08:25 PM

The issue you are having is because the image html is generated code, and so not bound to the jquery code

The easiest fix is to use .live(‘click’, function(){...}) instead (or .on() is recommended now, but it isn’t 100% the same)

http://api.jquery.com/live/

.on() isn’t quite the same, but should be used instead of .live() because you will end up making code that is instantly outdated if you use the deprecated .live() method.

See:
http://www.jquery4u.com/jquery-functions/on-vs-live-review/#.UHEFI1G4LTo
http://stackoverflow.com/questions/8477779/jquery-on-versus-live
http://www.andismith.com/blog/2011/11/on-and-off/
and a thousand more if you search on Google!

I always liked .live() because it was a instant swap for .bind(), but you gotta do what you gotta do. (unless you’re using an old version of jQuery and then you don’t gotta do what you can’t do)

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application