Hiding the link after the first click on html.disable link.in html.java

I pass some values ​​through the "How" link, I want to set the property so that the link is hidden or disabled if it is clicked once .. tried this code
onclick="this.style.display='none';"

But this does not seem to work. Please help how to post js or any other alternative method.

 <a href="like1?sellerid=<s:property value="id"/>&property_id=<s:property value="p_id"/>"onclick="hide">Like</a>;' 
+5
source share
3 answers

As said, these functions are best implemented using javascript. First assign a valid identifier for the link and do the following:

 //create a function for the click like: $('#buttonId').click(hideButton); 

Then in your javascript code:

 function hideButton(){$('#buttonId').css({'visibility':'hidden'})}; 

Remember to import the jquery library and import .js when your code has been displayed, unless you use the .ready function.

Edit: note that in the same order as before, you still get the field where the link was, but it appears hidden.

+3
source

If you need to pass some values, as well as hide the i element, you should use ajax. When you pass the url attribute to href, it redirects you to this page. A java script function might work better. Calling javascript function in onClick event e.g.

 <a href="#""onclick="hide()">Like</a> <script> function hide(){ // ajax call to send parameter // hide element } </script> 
0
source

Define a class for the anchor tag and custom ajax mail to send the request to, and then you can just hide the element with hide() .

See below for an example:

 $(".like").on("click", function (e) { e.preventDefault(); $.post(this.href); $(this).hide(); }); 
 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="like" href="like1?sellerid=-1">Hide me</a> 
0
source

Source: https://habr.com/ru/post/1236680/


All Articles