Hiding <p> field in javascript <p>Here's my code for gathering titles/posts from reddit's api:</p> <pre><code> $.getJSON("http://www.reddit.com/search.json?q=" + query + "&amp;sort=" + val + "&amp;t=" + time, function (data) { var i = 0 $.each(data.data.children, function (i, item) { var title = item.data.title var url = item.data.url var id = item.data.id var subid = item.data.subreddit_id var selftext = item.data.selftext var selftextpost = '&lt;p id="post' + i + '"&gt;' + selftext + '&lt;/p&gt;&lt;br&gt;' var post = '&lt;div&gt;' + '&lt;a href="' + url + '"&gt;' + title + '&lt;/a&gt;' + '&lt;/div&gt;' results.append(post) results.append(selftextpost) i++ }); }); </code></pre> <p>Basically every post (selftext) is assigned a different paragraph id (post0, post1, post2, etc) for every result that's pulled. I'm also going to create a "hide" button that follows the same id scheme based on my i variable (submit0, submit1, submit2, etc). I want to write a function so that based on which button they click, it will hide the corresponding paragraph. I've tried doing an if statement that's like if("#hide" + i) is clicked, then hide the corresponding paragraph, but obviously that + i doesn't work. How else can I tackle this?</p>