我有一个工作站点,并且每次单击链接时都尝试显示类“ start_hidden”的元素。(这里是一个较大示例的http://jsfiddle.net/t29w5cb3/,但我在下面包括了所有必需的代码)>
jquery:
<script>
$(document).ready(function(){
$(".job_link").click(function(){
$("start_hidden").show();
});
});
</script>
html:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="job_results_nested_grid">
<div class="job">
<h2><a class="job_link" href="#">Delivery - Pizza Hut</a></h2>
<p class="job_p"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur corporis dolor eius facere laboriosam libero minima necessitatibus nobis nulla, officiis optio quis tempore vel. Exercitationem harum ipsum perspiciatis unde voluptate!</p>
<p class="start_hidden">salary: 12</p>
</div>
<div class="job">
<h2><a class="job_link" href="#">Delivery - Pizza Hut</a></h2>
<p class="job_p"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur corporis dolor eius facere laboriosam libero minima necessitatibus nobis nulla, officiis optio quis tempore vel. Exercitationem harum ipsum perspiciatis unde voluptate!</p>
</div>
</div>
</body>
css:
.start_hidden{
display: none;
}
</style>
我在做错什么吗?我觉得这可能与我的CSS有关,但是我是jquery新手,所以我不确定
答案 0 :(得分:1)
$("start_hidden").show();
更改为
$(".start_hidden").show();
答案 1 :(得分:1)
您需要使用$(this).parents('.job')
,因为这两个元素都是<div class="job">
的子元素,并且您只想在单击的元素旁边显示
$(".job_link").click(function(){
$(this).parents('.job').find(".start_hidden").show();
});
答案 2 :(得分:0)
您缺少课程
$(".start_hidden").show();