سؤال

I'm trying to style the pager of a WebGrid element in Asp.Net MVC. The pager looks something like this:

<td colspan="4">
    <a href="#"><<</a>&nbsp;
    <a href="#">1</a>&nbsp;
    &nbsp;2&nbsp;
    <a href="#">3</a>&nbsp;
    <a href="#">>></a>&nbsp;
</td>

Although I can easily style the a elements, I'm having problems styling the "untagged" text (in this example, the 2). Is there a way I could target/select just the text and not the anchor elements? (JSFiddle provided)

هل كانت مفيدة؟

المحلول

I am not aware of any CSS selector that can target text nodes. You can use JavaScript or jQuery to wrap the active link inside a tag; then style it appropriately. Here is an example:

$(".pagination").contents().filter(function () {
    return this.nodeType === Node.TEXT_NODE && /\d+/.test(this.nodeValue);
}).wrap("<b></b>");

Demo here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top