简体   繁体   English

如何使用Jquery更改特定的div样式?

[英]How do I change a specific div style using Jquery?

the image represents the html code: 该图像表示html代码:

fullimage: http://i.stack.imgur.com/izqd6.png and this is my jquery code: fullimage: http ://i.stack.imgur.com/izqd6.png,这是我的jquery代码:

$(".transaContentEdit").click(function(e) { 
   alert($(this).closest(".transe_row").find(".edit_transa").attr("class"));
   $(this).closest(".transe_row").find(".edit_transa").show();

});

the alert returns me undefined; 警报使我返回未定义状态; The main idea is when i click on .transaContentEdit , i want to "show" the .edit_transa class. 主要思想是当我单击.transaContentEdit ,我要“显示” .edit_transa类。 What is wrong with my code ? 我的代码有什么问题?

$(".transaContentEdit").click(function(e) { 
   $(this).parents(".transe_row").parent().find(".edit_transa").show();
});

.transaContentEdit is at the same level with .edit_transa so you can't use .find() because .find() is use just to find childs from an element. .transaContentEdit.edit_transa处于同一级别,因此您不能使用.find(),因为.find()仅用于从元素中查找子项。 You can try something like this: 您可以尝试如下操作:

$(".transaContentEdit").click(function(e) {
     alert($(this).closest(".transe_row").parent().find(".edit_transa").attr("class"));
     $(this).closest(".transe_row").parent().find(".edit_transa").show();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM