Attribute binding in Svelte.js
In this post we will give you information about Attribute binding in Svelte.js. Hear we will give you detail about Attribute binding in Svelte.jsAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to bind HTML attributes in svelte.
This is our starting code.
<script> let src = "rose.jpg";</script><h1>This is my first svelte app</h1><img />
To bind the attributes in svelte we need to use curly brace syntax { } so that it can evaluate the JavaScript expression.
<script> let src = "rose.jpg";</script><h1>This is my first svelte app</h1> // attribute binding<img src={src} />
Shorthand attributes
If the attribute name and value is matched like in above code src={src} it can be replaced by {src}.
<img {src} />
Similarly, we can bind other HTML attributes by using { } curly brace syntax.
<script> let disabled = true; let google = "https://www.google.com"</script>//disabled button<span><button {disabled}>Click</button><a href={google}>Google</a>
Hope this code and post will helped you for implement Attribute binding in Svelte.js. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs