My code programmically creates <span> nodes with a custom ID. I am trying to access a specific one using Jquery but it doesn't want to work for me.
the html:
<div id="container">
<div id="header">
<span id="menu">
</span>
<center></center>
<span id="refresh" runat="server">
</span>
</div>
<div id="content" runat="server">
<ul id="list" runat="server"></ul>
</div>
<div id="article" runat="server">
</div>
</div>
the jquery:
$(document).ready(function () {
$("a").click(function () {
var post = $(this).data('postid'); //this works and returns the postID selected.
$('#list').slideUp(); //this hides all the anchor tags
$('#' + 'post' + post).show(); //This is what is not working
});
});
the .net c#
foreach (SyndicationItem item in feed.Items)
{
subject[count] = item.Title.Text;
date[count] = item.PublishDate.DateTime.ToString();
summary[count] = item.Summary.Text;
list.InnerHtml += "<a href=\"#\" data-postid=\"" + count +"\"><li id=\"post" + count + "\"><span id=\"bold\">" + subject[count] + "</span><br>" +
"<span id=\"posted-date\">Posted on: " + date[count] + "</span></li></a>";
article.InnerHtml += "<span style=\"display: none;\" class=\"post\" id=\"post" + count + "\">" + summary[count] + "</span><br>";
count++;
}
Pretty much when I click one of the anchor nodes, it grabs the postID and hides the list of anchor tags I have and is suppose to display(un-hide) the post that has the postID.
Please let me know if u need any more information.
alert("post = " + post);at line 4 do you get what you are expecting?$(this).data('postID')postID.What if someday html introduces an attribute with the same name?? Instead you should usedata-ATTR_NAME. You can take a look at this link