It’s possible to combine my jQuery below in simple code?
$(document).ready(function () {
$("a.type").live('click', function () {
var type = $(this).data("id");
$('#advertisements').load("ads.php?" + type);
});
$("a.maincat").live('click', function () {
var maincat = $(this).data("id");
$('#advertisements').load("ads.php?" + maincat);
});
$("a.subcat").live('click', function () {
var subcat = $(this).data("id");
$('#advertisements').load("ads.php?" + subcat);
});
$("a.region").live('click', function () {
var region = $(this).data("id");
$('#advertisements').load("ads.php?" + region);
});
$("a.byuser").live('click', function () {
var byuser = $(this).data("id");
$('#advertisements').load("ads.php?" + byuser);
});
});
and according to this code how do I load default content is by $('#advertisements').load("ads.php?" + 1);
Currently need to click for load a specific content.
Let me know
Description
You can use multiple selectors because you always need the data from the
idattributeand load everytime from the same script.
Sample
More Information
Update
Are you sure that you want
$(this).data("id")and not theìdvalue of the element that get clicked ?If you want the value from the
idattribute do thisvar id = $(this).attr("id");instead of
var id = $(this).data("id");– jsFiddle Demonstration