Updates the identicon in a specified element.
jdenticon.update(element|selector[, hash|value[, config]])
Availability | Browser | Node.js |
---|---|---|
jdenticon.update() | Yes | No |
The following example shows how to use the update
method to render an icon on demand without using the data-jdenticon-value
or data-jdenticon-hash
attribute.
Update icon
<canvas id="identicon" width="100" height="100"> </canvas> <script src="https://cdn.jsdelivr.net/npm/jdenticon@3.2.0/dist/jdenticon.min.js" integrity="sha384-yBhgDqxM50qJV5JPdayci8wCfooqvhFYbIKhv0hTtLvfeeyJMJCscRfFNKIxt43M" crossorigin="anonymous"> </script> <script> jdenticon.update("#identicon", "ff8adece0631821959f443c9d956fc39"); </script>
element|selector
can be either a <canvas>
element, an <svg>
element or a CSS selector to a <canvas>
or <svg>
element. If the selector evaluates to multiple elements, all elements are updated.
If the second parameter hash|value
contains a hexadecimal string of at least 11 characters it is considered a valid hash and used as base for the icon. If it contains any other value it is hashed using SHA1. If null
or undefined
is specified, or if the parameter is omitted, the function will in first hand look for a data-jdenticon-hash
attribute on the element, in second hand for a data-jdenticon-value
attribute.
config
(from v2.2.0) specifies an optional configuration object. If no configuration is specified, the global configuration is used. For backward compability this parameter can also be a padding value in the range 0.0 to 0.5.
The methods jdenticon.updateCanvas()
and jdenticon.updateSvg()
do the same thing as this method, but do only support a single element type. If you only use a single element type (<svg>
or <canvas>
), then the more specific methods are preferred since they provide better code optimization opportunities for bundlers, keeping your JavaScript bundle as small as possible.
The following priority order is used to resolve the icon configuration when the icon is drawn:
config
parameter passed to update()
jdenticon.configure()
.jdenticon_config
global variable.