Posts

Showing posts from November, 2012

JQuery - Things to learn - ID selector with a nested HTML markup string inside Javascript

At first I thought since JQuery is so good that it could pin point to a tag using the ID selector very easily, then it shouldn't be a problem to do the same thing within a client side script as follow. ... var htmlString = " <div id=\"outerpanel\"> <div id=\"innerpanel1\"> Something here</div> <div id="\innerpanel2\"> another thing here</div> </div> "; var contentOne = $(htmlString).filter('#innerPanel1').html(); alert(contentOne); ... So I did try this out, and found out that it didn't work at all.  It turns out that in order to search for the panel, it has to traverse through the child within the DIV with the ID outerPanel.  I have no idea on why is that so, so I just going to remember next time that in the case of manipulating an object using JQuery within a script, I'll have to traverse through the children elements in order to look for it.