Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would help to be a bit more specific but I'm always down to help a greenhorn.</p> <p>There are plenty of ways to disable a link using jquery and javascript. What you are looking to do is access the disabled attribute (e.g. disabled='disabled'/disabled="true"/just plain old disabled in your code).</p> <p><strong>Jquery Solution</strong></p> <p>First of all, if you want to dynamically change what happens when the user clicks the link, you will need to use a javascript link, a link that calls a javascript function when you click it.</p> <pre><code>&lt;a id="myId" name="myName" href="javascript:void(0)" onClick="function()"&gt;BlahBlah&lt;/a&gt; </code></pre> <p>Next, you can run anything on page load using the following and will need to do so to immediately disable the links with my code.</p> <pre><code>$( document ).ready(function() { //code and function calls go here }); </code></pre> <p>Otherwise, jquery or javascript can be used to simply change a DOM Element (the document element).</p> <p>To see why you use this method, read <a href="https://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0/134865#134865">this</a></p> <p>You can reference a link attribute using its tag (e.g. a, div;etc.) in the following format. ('tag').event(function(){}); To access a specific link, you need to give it an id. The format would become ('#id').event(function(){});</p> <p>You are looking for something that looks like the following code.</p> <pre><code>$('a').click(function(){return false}); </code></pre> <p>You may also be looking to filter your link requests.</p> <pre><code>$('a').click(function(){return ($(this).attr('disabled')) ? false : true;}); </code></pre> <p>This code uses the turnary operator((condition)?perform if true:else perform if false) and a return statement to change the status on a click.</p> <p>If you wish to add the link to a list so you can track what is clicked, that is possible to. That way, if you disable after clicking, you can keep track of what has been disabled. The following code can be manipulated for use in enabling or disabling particular page sections but javaScript is always open to injection or scraping. It is better to use server side script in that instance. This is mostly so you get the idea of what is going on.</p> <pre><code>var disabled=[] ... $('a').click(function(){ var isSet=$(this).attr('disabled'); if(isSet==false) { disabled.push(event.target.id); } return false; }); </code></pre> <p>To disable on the load simply add an onload tag to your script which should be in a .js file for ease of reading and security of your code.</p> <p>More information is available here <a href="https://stackoverflow.com/questions/5085584/disable-a-hyperlink-using-jquery">disable a hyperlink using jQuery</a></p> <p><strong>JavaScript Solution</strong></p> <p>You can change the status of the link by accessing all of the links on the DOM (like XML) using tag names and then setting the disabled attribute.</p> <pre><code>var list=document.getElementsByTagName("a"); for(var i=0;i&lt;list.length;i++) { list[i].disabled='disabled'; } </code></pre> <p>This code accesses all of your links and uses a for loop to disable them using the disable attribute.</p> <p>If you wish to disable a particular link use the following which accesses an element by its Id. document.getElementById("id").disabled='disabled';</p> <p>To renable all of your links:</p> <pre><code>var links=document.getElementsByTagName("a"); for(var i=0;i&lt;links.length;i++) { links[i].removeAttribute("disabled"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload