Hi All, Hope you can help with this, it seems very simple but i havent quite figured out JS yet. Anyways, i want to be able to add a variable to what already looks like a variable (but that is not declared anywhere). This is the code... $("#comments").append("<tr><td>"+name+"</td><td>"+comment+"</td><td>"+json.response.dt+"</td></tr>") Code (markup): Where $("#comments") is, i want to be able to add a variable int at the end of comments so it will be like "comments88" or what ever. How is this done please? Alex
$("#comments").(xxx): xxx is the JQuery JS that will be execited on the element with the id "comments",. So do you mean that you want the javascript code to be executed on the element with the ID comments88
Nabil, pretty much yeah, im planning to use the code for many different comments so i need to change the id "comments" to allow for different instances, so which is why i want to add a variable to it. it might be comments88 or comments63 whatever variable is passed into the code. Thanks
simply replace the "#comments" string by "#commentsXX", just keep in mind that $("some_selector") is the jquery way to choose what element to execute code on (where "some_selector" is a string, a CSS/XPATH selector): $("div") : all divs $("#comment_123") : all comments that have the id comments_123 like this one <div id="comment_123">...</div> $("div .info"): all elements inside a div that have the info class ... Further reading
Hi Yes i know all this, what i cannot do and am asking help for is .... I already have the <div id="comment_1">...</div> <div id="comment_2">...</div> <div id="comment_3">...</div> setup but i cannot edit the $("#comment") to place a $("#comment_VARIABLEHERE") so the same code can be used for both 1 2 and 3.
var commentNum; $("#comments_"+commentNum).append("<tr><td>"+name+"</td><td>"+comment+"</td><td>"+json.response.dt+"</td></tr>") The above code will work. I feel you are trying to full out this variable name as well from the database if that is the case then you can assign the ids in the dynamic page itself and can input it here through this.parentNode.id