以下是我的HTML
<a href="/content/testsite/en_gb/home/acis.html" class="">Branding</a>
是否可以使用CSS访问锚标记的文本? 这样的事情是我想要的吗? html是动态生成的,所以请不要提及id或者有任何课程。
a[text='Branding']
{
}
答案 0 :(得分:1)
人们已经告诉过你,你不能在CSS中选择 text 。但是我认为有一些解决方法。 我不知道你想做什么,可能是坏事,但如果我是你,我会采取这种不良做法:
/*First you hide the text*/
a {
font-size: 0; /* hide text */
text-decoration: none !important; /* get rid of that awful underline */
}
/* then you insert a new element using :before */
a:before {
content: 'Branding'; /* This is the text you want for the new element */
color: #333;
font-size: 15px; /* Bring back the text inside the anchor for this new element */
font: 24px sans-serif;
}
小提琴:http://jsfiddle.net/tsu7z546/
$(document).ready(function(){
var brandingAnchor = $('a:contains("Branding")');
brandingAnchor.hide();
});
记住!每次编写jQuery代码时,您必须已经在页面上调用了jQuery库,就像这样:
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
//Your jQuery code goes HERE, just below the library
$(document).ready(function(){
var brandingAnchor = $('a:contains("Branding")');
brandingAnchor.hide();
});
</script>