V14.5.x - API Element.setAttribute("href", "value") not working
See original GitHub issueVersions:
- Vaadin / Flow version: 14.5.4
- Java version: 11
- OS version: Windows
- Browser version (if applicable): Chrome
- Application Server (if applicable): Tomcat 9.45
The Java API: Element.setAttribute("href", "https://vaadin.com/")
is not working. The URL still remain the previous setting “https://github.com/”
Below is html on view setting (.js)
<div >
<a id="mylink" href="https://github.com/" target="_self" ></a>
</div>
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
element.setAttribute is not a function - Stack Overflow
when using querySelectorAll(), treat this as an array, you need a 'for loop' to step through the different elements. eg. var link =...
Read more >setAttribute() not working - JavaScript - SitePoint Forums
I'm trying to experiment with this tutorial: https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute and when I incorporate ...
Read more >Element.setAttribute() - Web APIs | MDN
Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute...
Read more >How to get and set the attribute in lwc
Use setAttribute if you're exposing a property that should appear in the DOM. // myComponent.js import { LightningElement, api } from 'lwc'; ...
Read more >getElement().setAttribute('role', 'custom-role') isn't working ...
The workaround via a JavaScript call works though: button.getElement().executeJs("this.setAttribute('role', 'custom-role')");. Maybe the heading ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
With these steps to reproduce and the expected result I can say: the expected result is wrong.
to get the expected result the code
mylink.setProperty("href", "https://vaadin.com/");
must be used. You can do exactly the same via the Chrome inspector: select the element and call for it$0.setAttribute("href", "https://vaadin.com/");
Nothing will be changed in the DOM. But if you set a property$0.setProperty("href", "https://vaadin.com/");
then you will get what you expect.The attributes are not the same as properties, please read e.g. this: https://stackoverflow.com/questions/6003819/what-is-the-difference-between-properties-and-attributes-in-html?answertab=active#tab-top
It’s very important to provide at least this information in every ticket report:
This is a perfect example why it’s so important:
steps to reproduce:
StaffCompanyView.js
code snippet contains a lot of irrelevant information . There a lot ofimport
s (they are not related to the issue) there issharedStyles
import whose content is not known from the report and what’s worse it’s used in the body of the template. So it’s impossible to say whether it matters or not.There is no expected result ( even though it’s kind of implicit : negation of real result)
The actual result is not clear : there is only a DOM snippet.
Since a lot of things are missed I have to make my own steps to reproduce to guess what the issue in fact is:
MainView
:The expected result: the DOM snippet looks this way:
The actual result : the DOM snippet looks this way: