Shadowing Posted May 30, 2012 Share Posted May 30, 2012 Hey guys im having a wierd issue I have a ajax working menu that when you click on each item in the menu a div pops up. I'm trying to have each menu item use the same div. So this is pretty much what each menu item has. what happends is when I click on "li.planets" the div appears with its content and then I click "#close" and it clears the div makes it blank but for some reason when i click on "li.planets" again to show the div its blank instead of reloading the content. for my understanding using html should replace content every time right? $("li.planets").click(function(event) { $("div.child_window").show(0); $("a#close").click(function(event) { $("div.child_window").hide(0); $('div.child_window_content').html(""); $('div.child_window_menu').html(""); }); }); $("div.child_option1").click(function(event) { $.ajax({ url: "ajax/menu_planets.php?functions=planets_owned", type: 'POST', success: function(response) { $('div.child_window_content').html(response.display); } }); }); Link to comment Share on other sites More sharing options...
Shadowing Posted May 30, 2012 Author Share Posted May 30, 2012 oh maybe its because it remembers it was clicked? so the click activates each time Link to comment Share on other sites More sharing options...
justsomeguy Posted May 30, 2012 Share Posted May 30, 2012 It's not going to auto-run the click function, but you should move the definition of that outside of the click handler for the other item. The way it is now, it adds another click event to the close button each time the click on a menu item, so when they click close it may run that function 2 or 3 times depending on how many menu items they clicked on. Link to comment Share on other sites More sharing options...
Shadowing Posted May 31, 2012 Author Share Posted May 31, 2012 thanks for the reply. I decided to just use seperate divs hehe. I have another question though that is driving me crazy. If i place a input field on the screen after page load. Do i need to use live or something in order to grab its value with $('#production_tech').val() Link to comment Share on other sites More sharing options...
Shadowing Posted May 31, 2012 Author Share Posted May 31, 2012 yah thats my issue. i cant read the input. Not sure how to even google this. I must not be typing in the right words. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 31, 2012 Share Posted May 31, 2012 jQuery shouldn't cache the DOM or anything like that, when you run a command to get an element by ID it should use the current DOM. You may not be adding the field correctly. Link to comment Share on other sites More sharing options...
Shadowing Posted May 31, 2012 Author Share Posted May 31, 2012 im adding the field from a huge php string thats gets turned into JSON then $('div.technology_return').html(response.display); I dont understand why is it that i have to use live for clickable on elements being placed on the page after page load? isnt the reason i have to use live is so i can read the id of the clickable or is it just something else it needs that using live does Link to comment Share on other sites More sharing options...
Shadowing Posted May 31, 2012 Author Share Posted May 31, 2012 I dont know what i was doing earlier with testing with alerts but I'm able to read the field now Link to comment Share on other sites More sharing options...
Shadowing Posted May 31, 2012 Author Share Posted May 31, 2012 thanks for the help Link to comment Share on other sites More sharing options...
Shadowing Posted June 7, 2012 Author Share Posted June 7, 2012 I dont know if this is the same issue as i was having several days back with replacing content but I just ran into a issue again but this time I know whats going on. will try to explain this with out pictures lets say i have a div with a border around it named <div class='content'></div>when I replace content using $('div.content').html(response.display); instead of it placing the content inside the border it places it under the border first i changed the back ground color to something i can see and i notice that the back ground color goes a away when using html(). so then i added a border and sure enough its not even placing content with in the div tag. going to look through the html for errors but atm i have no idea. Also if I try to change the color of text it works.so its like the content is in the div tag but back ground color and borders are not working with it which is bad cause its the reason why my overflow isnt working how I need it too cause its not pushing content down Link to comment Share on other sites More sharing options...
Shadowing Posted June 7, 2012 Author Share Posted June 7, 2012 what really doesnt make sense is. im using html() to replace the content in the first box which works. Really wierd how it stops working when i run html() a 2nd time Link to comment Share on other sites More sharing options...
Shadowing Posted June 7, 2012 Author Share Posted June 7, 2012 ahh I figured out my problem lol. the content i was placing in the box was absolute position. I forgot i did that lol. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.