# j-Selected

> The component can set a specific class to a specific element according to the simple condition.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 737d8475f3a8d262c76dfd4c597e8466405344cbe857c1e4a9cb0a0b1d822dd5
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

The component can set a specific class to a specific element according to the simple condition.


__Configuration__:

- `class {String}` is a class name for selected element (default: `selected`)
- `selector {String}` is a jQuery selector (default: `a`)
- `attr {String}` attribute for comparing (default: `if` and it means `data-if`)
- `attror {String}` attribute for secondary comparing (default: `or` and it means `data-or`)
- `datasource {String}` a path to data-source for list of items
- `delay {Number}` a delay for rel-selecting of value (default: `50`)

__Usage__:

Each nested element according to the `selector` must have defined `data-if` attribute. It works only with `strings` values.

Use it with `<ui-component name="selected">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<style>
	.selected { font-weight: bold; }
	nav a { display: block; }
</style>

<nav>
	<ui-component name="selected" path="common.page">
		<a href="#users" data-if="users">Users</a>
		<a href="#products" data-if="products">Products</a>
		<a href="#settings" data-if="settings">Settings</a>
	</ui-component>
</nav>

<script>

	SET('common.page', 'products');

	window.onhashchange = function() {
		SET('common.page', location.hash.substring(1));
	};

</script>
```
