Best unobtrusive way to add JQuery confirm to an arbitrary element

痴心易碎 提交于 2019-12-01 13:10:12

Use the data- attribute, see here

<a href='#' data-confirm="Are you sure?">Some Link</a>

Answer to 1: Yes they will.

Answer to 2: You could add CSS class called requires-confirm and add data-description or data-meta attribute with additional text that you'd use in your handler.

Why both?

In case you have more than one functionality integrated in your page. CSS class tells which functionality should be added and data- attribute holds metadata to use.

If you'll only be using one single functionality, you can easily omit CSS reference and just use the data- attribute of course.

personally, I use a specific class for things like that.

The main reason is that they are easy to select with something like $('.confirm').each() or better $('.confirm').youConfirmPlugin(). Moreover, a css is easily added in a css file (where it belongs).

if extra data is needed, then yes, use the data attribute in combination with the class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!