Во-первых, я думаю, что :not()
терпит неудачу, потому что вы используете числа в качестве идентификаторов, что недопустимо в HTML4.Все атрибуты id
должны начинаться с буквенного символа.Вы можете добавить к своим идентификаторам префикс r
, например:
<div class="records" id="r1">
Во-вторых, вы можете сделать это намного эффективнее, используя метод .not
:
$(".controls a").click(function() {
var action = this.class;
var record = $(this).closest(".records")[0]; // get the DOM element of the ancestor .records
//Now send post request and database things
//function(data) { //After this stage
$(this).children("img.r1").show(); //show the active image
$(this).children("img.r0").hide(); //hide the inactive image
$("div").not(record).find("a.special img.r1").hide(); //hide all the active image except this one
$("div").not(record).find("a.special img.0").show(); //show all the in-active image except this one
// } //
});
Обратите внимание на использование
this.class
для замены $(this).attr('class')
.closest('.records')
для поиска ближайшего предкового элемента с классом records
[0]
для получения элемента DOM из выбора jQuery .not(record)
для удаления элемента record
из набора .find()
, чтобы найти все дочерние элементы, соответствующие определенному селектору