How to Select <A> Only When There's No Text Around It

Can I select a only when there's no text around it?

The simple answer is: no, you can't.

As explained here, here and here, there is no CSS selector that applies to the text nodes.

If you could use jQuery, take a look at the contains selector.

CSS - select element without text inside

Indeed, there isn't a selector for elements with no text node children (or descendants).

In Selectors level 4 it may be possible with

.to-select:not(:has(:not(:empty)))

or, to account for inter-element whitespace,

.to-select:not(:has(:not(:blank)))

but since :has() may not be fully available in the fast profile, you may not be able to use it in CSS even once Selectors level 4 is implemented.

Using JS is your best bet, unfortunately. The above selector with :empty will work in jQuery today, but even once :has() is implemented natively, for this specific use case you'd only be able to use it in document.querySelectorAll() at best.

How to not select blank text in tkinter text widget?

It's not really an "area" being selected: the Text object contains (and
selects) characters, not areas. It's important to distinguish the
characters being selected, and their representation on the screen.

The last character in every line is a newline '\n' (that's actually what
defines a line). When you move the mouse beyond the dot '.' (to the right),
you're including the newline in your selection.

Now, the Text widget normally inverts foreground and background colors to
indicate that a character is selected, but the newline is not explictly drawn
as a character, it's actually invisible (apart from the fact that the text
jumps to the following line). These blank areas that bother you are just the
Text widget's way of telling you that you've selected the newline character,
and I don't think you can change this display behaviour.

Using .text() to retrieve only text not nested in child tags

I liked this reusable implementation based on the clone() method found here to get only the text inside the parent element.

Code provided for easy reference:

$("#foo")
.clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text();

How do I disable text selection with CSS or JavaScript?

<div 
style="-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;"
unselectable="on"
onselectstart="return false;"
onmousedown="return false;">
Blabla
</div>

How to select rows with no matching entry in another table?

Here's a simple query:

SELECT t1.ID
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t2.ID IS NULL

The key points are:

  1. LEFT JOIN is used; this will return ALL rows from Table1, regardless of whether or not there is a matching row in Table2.

  2. The WHERE t2.ID IS NULL clause; this will restrict the results returned to only those rows where the ID returned from Table2 is null - in other words there is NO record in Table2 for that particular ID from Table1. Table2.ID will be returned as NULL for all records from Table1 where the ID is not matched in Table2.

Prevent text selection after double click

function clearSelection() {
if(document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}

You can also apply these styles to the span for all non-IE browsers and IE10:

span.no_selection {
user-select: none; /* standard syntax */
-webkit-user-select: none; /* webkit (safari, chrome) browsers */
-moz-user-select: none; /* mozilla browsers */
-khtml-user-select: none; /* webkit (konqueror) browsers */
-ms-user-select: none; /* IE10+ */
}


Related Topics



Leave a reply



Submit