var iValuation = $('div[class~="iValuation"]');
Can anyone tell me what the purpose of the tilde in this instance is? I've not come across it before and haven't been able to find any reference to it online.
Since that string is passed to the jQuery function, and it doesn't look like a piece of HTML, it is a selector.
Specifically one of the attribute selectors:
Represents an element with the att attribute whose value is a whitespace-separated list of words, one of which is exactly "val". If "val" contains whitespace, it will never represent anything (since the words are separated by spaces). Also if "val" is the empty string, it will never represent anything.
Tiled used as selector means
Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.
More from doc:
This selector matches the test string against each word in the attribute value, where a "word" is defined as a string delimited by whitespace. The selector matches if the test string is exactly equal to any of the words.
<input name="man-news" /> <input name="milk man" /> <input name="letterman2" /> <input name="newmilk" />
$('input[name~="man"]') will select only second
input, because its attribute
name is separated by
For detail see here
$ is the
jQuery selector function, which contains a
CSS3 Selector String: According to the
CSS3 Selector Definition, the selector you encountered selects:
E[foo~="bar"] an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar"
DOM. Because the Tilde is wrapped in a string, it is not working as an operator.
In case you're wondering about the difference between
~ will match only with whitespace around (e.g. 'foo bar' but not 'foo-1')
* will match with our without whitespace around (e.g. 'foo bar' and 'foo-1')
~ - Attribute Spaced Selector
* - Attribute Contains Selector
©2020 All rights reserved.