GoodLife Posted July 7, 2009 Share Posted July 7, 2009 I'm fairly new to jQuery and trying to write some code to replace the inner HTML of an element. The element is dynamically created. I would expect the inner HTML of the element with the id of type+".title" to be "hello" after the code is run but it is "test1". The plain javascript is working but the jQuery isn't. Any ideas about why the jQuery isn't working would be much appreciated. Thanks! function edit(type){ var sectionId = "#"+type; if($(sectionId).attr("type") == "section") { document.getElementById(type+".title").innerHTML = "test1"; $("#"+type+".title").html("hello"); }} Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 7, 2009 Share Posted July 7, 2009 In your HTML code, is the ID of the element "type.title" or "type"? (whatever type is) Link to comment Share on other sites More sharing options...
GoodLife Posted July 7, 2009 Author Share Posted July 7, 2009 In your HTML code, is the ID of the element "type.title" or "type"? (whatever type is)type is a variable passed to the function so if type were "test" the id would be "test.title" Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 10, 2009 Share Posted July 10, 2009 Avoid using dots in IDs. Try an underscore (_) instead. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.