通过单击链接在另一个ID中显示特定的id或类

时间:2015-03-05 05:10:13

标签: jquery html

我有这些链接

<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#portofolio">Portofolio</a> 
<a href="#contact">Contact</a>

我希望用户点击其中任何一个,并在另一个div中显示相同的div id。另外,我希望第一个孩子被移除。

<section id="part" class="part">
<div id="home"class="home">first Content </div>
<div id="about"class="about"><p>Another type of information</p></div>      
<div id="portofolio"class="portofolio"><p>oh heres another</p></div>      
<div id="contact"class="contact"><p>aaaand another one</p></div>      
</section>

我使用jquery来做到这一点,但是我没有到达那里。我相信你们都知道的更好。

https://jsfiddle.net/xm8sLcuy/

以上是我在这里的内容 我提前感激。

1 个答案:

答案 0 :(得分:0)

使用以下脚本

$(document).ready(function(){

$("#part").find("div").hide();

$("a").click(function(event){
  event.preventDefault();
  var divID = $(this).attr("href");
  var result = divID.substring(divID.length, 1);
  $("#part").find("div").hide();    
  $("#"+result).show();
});

});

另请参阅JSFiddle

希望这有帮助。

相关问题