i wrote showDataSubject() >function using javascript to fetch data from sql table.by jquery.ajax()
function showDataSubject() {
$.ajax({
type: "POST",
url: "subject.aspx/showDataSubject",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$('#PanelSubjectMenu').html(msg.d);
}
});
}
c# method
[WebMethod]
public static string showDataSubject()
{
SqlToXml sqlToXml = new SqlToXml();
// sqlToXml.CreateSubject();
return sqlToXml.CreateSubjectTreeViewClient();
// htmlShowData = sqlToXml.CreateSubjectTreeViewClient();
}
Saved in fiddle
http://jsfiddle.net/H5guu/
but the click() method did not work.(in the fiddle it worked correctly)
but in my application it did NOT work.
$('#PanelSubjectMenu span').click(function() {
$('#subjectTree span').css('color', 'black');
$(this).css('color', 'red');
});
What’s the reason?
Try to use delagation for jquery 1.7+: