I am using an a tag with an href that calls an id to do its function
<a href="#openModal">Abrir</a>
It happens that I can't use an a tag at the moment because all my work is damaged, I want to know what other tag I can use and that href works, since I have tried to put it in other tags but it doesn't work for me.
It's not possible to use the attribute on another tag
html
, you could in theory use it on another element, but it won't work and it will always validate as wrong.I am afraid that the solution to your problem is contextually different, but we would need more information about your project, specifically, how does it "hurt" to have this attribute in the link? o What is the script
js
you are using to handle the event? What is the html and css structure of your page? because in theory it shouldn't affect having more than one tag<a>
in the logic of calling a modal.Now, also, the truth is that it is not necessary to specifically use the attribute
href
for the modal to work, in fact you could achieve the same event with another attribute of type data, exampledata-href="#ejemplo"
.The label
<a>
doesn't affect what it looks like, with styles you can make it look like a button, it can "wrap around" an image without affecting it... whatever you need:As you mentioned in the comment, worth the redundancy, the href attribute is only used to open a modal, and you say that the tag
<a>
gives you problems, so let's do another solution so that you open the modal without the tag<a>
and obtain the id of the modal you want to open :If you noticed, I created two options, one with Jquery and the other with pure Js , use the one that suits you best, the idea is to obtain the id by obtaining the href attribute of the div in this case , although href is not an attribute of the div itself, you can declare it and use it as a pseudo-attribute, that means that it will not affect you in the div's own behaviors, if you also pay attention, create another attribute called data-href so that you can see that you can create an attribute with a name that suits you, in these times it will be is using the data-algo a lot, you can use that to get the id of the modal or use the href as you please, once you get the id you can invoke your modal and make it open with a modal's own method, example in bootstrap you would open it like this:
$("#modal").modal("show");
, I don't know what plugin are you using but you already have the general idea, get the id and then call the method that would open your modal. I hope it works for you.Example calling a modal with Bootstrap: