funstad Posted March 21, 2016 Share Posted March 21, 2016 hello, i am working with jquery, thake a look at my jsbin code. when you click on the smile icon there popups a screen. Now the IMG field should be the IMG SRC. For some reason i cant get it to display the IMG SRC, any ideas?? https://jsbin.com/lelaxam/1/edit?js,output kind regards Link to comment Share on other sites More sharing options...
funstad Posted March 21, 2016 Author Share Posted March 21, 2016 Update: when you remove the <a> tag around the image it will show the image src, but i cant remove them for my project. any ideas? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 21, 2016 Share Posted March 21, 2016 First, if you look at your browser's console you'll notice that if you open the box and click save multiple times, it runs the save function multiple times. The first time you click save it runs it once, the second time it runs it twice, the third time it runs it 3 times, etc. That's because every time you show the edit box you attach another function to the save button. So if you show the save box 5 times then you have 5 save functions running when you click on the save button. Don't attach the event handler for the save button when you show the box, you only need to attach it once. Second, add some more console.log statements. Check things like this: $("#sim-edit-testtest .url") and this: $(".sim-edit-box-content-field-input.imgurl") Link to comment Share on other sites More sharing options...
funstad Posted March 21, 2016 Author Share Posted March 21, 2016 i have this right now (https://jsbin.com/lelaxam/edit?html,js,output) using the folowing code to display the image link $("#sim-edit-testtest .image").val($('img').attr("src")); The only issue now is that it takes the FIRST link it finds, how can i select the img src from the object i click on ? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 21, 2016 Share Posted March 21, 2016 Your click handler can figure out which element was clicked on, and if necessary you can go up the parent tree to find the relevant image. I believe that, inside most jQuery event handlers, $(this) refers to the element that fired the event. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now