Question

On a web site I have created, I present a tag cloud. I wish to allow the user to choose some of the tags so that I can perform some further action with them. For various reasons, I want the choice to be made by right clicking on a teg.

So, to sum it up, I wish to use javascript to catch any word that is right-clicked. Bearing in mind that I barely know JS, is there an easy way to do it?

Thanks in advance

Was it helpful?

Solution

Here is a sample

<div id="cloud-tag-container">

        <span class="tag">Tag 1</span>
        <span class="tag">Tag 2</span>
        <span class="tag">Tag 3</span>

    </div>

<script type="text/javascript">


        document.getElementById('cloud-tag-container').oncontextmenu = function (evt) {
            if (evt.target.classList.contains('tag')) {
                // then you right clicked on the span with class 'tag'
                // perform your actions here
            }
        }

    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top