L
L
lavezzi12015-10-02 11:08:59
css
lavezzi1, 2015-10-02 11:08:59

How to make a link to call a modal window?

You need to make a link that calls the window. What tag to use? span, div, or button styled like a link? What will be semantically and true?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dartess, 2015-10-02
@lavezzi1

Never use links for anything other than following a link, and even more so DO NOT use onclick="return false". Do not violate the semantics of layout. The link must link. And the action to open the modal can be hung on any element - whether it's a span or a div, or even better - a button. Positioning the button outside the form is perfectly valid, the comment above is incorrect. Using button will give one more advantage - native switching to the button by tab.

D
Dmitry Kovalsky, 2015-10-02
@dmitryKovalskiy

Yes, you can link. What's the problem?

<a href=# onclick= return false(чтобы не произошел переход)></a>

The main thing here is to make sure that the link does not work as a link. And there are enough tools for this.

V
Vitaly Inchin ☢, 2015-10-02
@In4in

Depends on what's in that window. If some other page, then I would do something like this:

document.querySelector("a").onclick = function(e){ 
  e.preventDefault(); 
  window.open(this.href); 
}

So that search engines can also parse the link to this page, and users without JS can open it.
Otherwise, I would use span , but I don’t know what you have there and how. From the semantic side, the only caveat is that you need to use the button only within the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question