不使用Javascript或<a> or href

时间:2015-06-30 05:41:39

标签: javascript jquery html css twitter-bootstrap

I'm having a small issue with a div .

I have a font awesome icon in my div that i want to be clickable without using the a or href tag .

Javascript - i would prefer not unless its the only option

<h3 class="panel-title">

<div class="panel-x" data-toggle="collapse" data-target="#collapseUser">

Title

</div> 

</h3>

I want to make the div class : panel-x clickable .

Now , when i hover on it , the cursor just changes to the I symbol instead of the hand .

The icon for the div is generated in css.

.panel-x:after {
    font-family: 'FontAwesome';
    content: "\f057";
}

5 个答案:

答案 0 :(得分:3)

尝试使用cursor: pointer

.panel-x {
  cursor: pointer; /* hand cursor */
  border: 1px solid grey;
  background: ghostwhite;
  display: inline-block;
  padding: 4px 11px;
  border-radius: 4px;
  box-shadow: 0px 1px 1px;
  font-family: 'Trebuchet MS';
}
.panel-x:hover {
  box-shadow: 0px 1px 3px;
}
.panel-x:active {
  box-shadow: 0px 1px 3px inset;
}
<div class="panel-x" data-toggle="collapse" data-target="#collapseUser">Title</div>

<div class="panel-x" data-toggle="collapse" data-target="#collapseUser">There goes a long text</div>

答案 1 :(得分:1)

你试过cursor: pointer吗?

答案 2 :(得分:1)

使用jquery你可以这样做

$(".panel-x").on('click',function(e){
  // code logic here
  e.preventDefault();    
});

答案 3 :(得分:1)

试试这个     .panel-X {         font-family:&#39; FontAwesome&#39 ;;         内容:&#34; \ f057&#34 ;;         游标:指针;     }

答案 4 :(得分:1)

尝试这个

CSS:

.panel-x:after {
    font-family: 'FontAwesome';
    content: "\f057";
}


div.panel-x { cursor: pointer; cursor: hand; }



JS:

$(document).ready(function(){
    $("div.panel-x").on('click',function(){

        console.log("clicked");
    })
})