JavaScript How do I get a hidden value from a <td> with jquery hidden value from javascript,hidden value in html,hidden value

Can't find the answer anywhere. I don't know how to get a hidden value from a <td> on jquery.

<td class='equis' value='8'>X</td>

I also tried putting the value='8' on a <span>, a <p> amongst others.

$('.equis').click(function(){
   var compra_id = $(this).val();
   alert("ID: "+compra_id);
});

But compra_id doesn't get the "8" value.

I've tried to solve it in a couple of other different ways but seems to me that the way to go should be something similar to this. What I want to do is actually very simple; hope someone can help me out.

Answer:1

value can only be retrieved using val() on form controls.

Suggest using a data- attribute instead since value is meaningless

<td class='equis' data-value='8'>X</td>

Then use

$('.equis').click(function(){
   var compra_id = $(this).data('value'); 
   alert("ID: "+compra_id);
});
Answer:2

you can't use val() for table data. try this instead:

$('.equis').click(function(){
    var compra_id = $(this).attr('value');
    alert("ID: "+compra_id);
});
Answer:3

You should use attr like following.

$('.equis').click(function(){
   var compra_id = $(this).attr('value'); 
   alert("ID: "+compra_id);
});
Answer:4

here is javascript what i have tried function toggle(clicked_id,name) { alert(clicked_id); alert(name); var text = document.getElementById("clicked_id"); var ele = document....

here is javascript what i have tried function toggle(clicked_id,name) { alert(clicked_id); alert(name); var text = document.getElementById("clicked_id"); var ele = document....

I have number of different buttons on my website and I want to assign different task to each button, currently I am referencing them one by one using getElementByID and because I have so many buttons ...

I have number of different buttons on my website and I want to assign different task to each button, currently I am referencing them one by one using getElementByID and because I have so many buttons ...

  1. loop through buttons javascript
  2. loop through buttons vba
  3. loop through buttons jquery
  4. loop through buttons
  5. loop through buttons vb.net
  6. loop through buttons java
  7. loop through buttons android
  8. loop through radio buttons javascript
  9. loop through option buttons vba
  10. loop through radio buttons jquery
  11. loop through command buttons vba
  12. c# loop through buttons on form
  13. loop through all buttons jquery
  14. c# loop through buttons
  15. loop through radio buttons
  16. tkinter loop through buttons
  17. wpf loop through buttons
  18. selenium loop through buttons
  19. loop through radio buttons php
  20. excel loop through buttons

Just trying to get the current index of the touchable highlight that is pressed. For some reason it is only returning the highest number in the array. Any ideas? render: function() { var images = ...

Just trying to get the current index of the touchable highlight that is pressed. For some reason it is only returning the highest number in the array. Any ideas? render: function() { var images = ...

  1. react native which language
  2. react native which ide
  3. react native which database
  4. react native what is
  5. react native where is console log
  6. react native what is expo
  7. react native what is flex
  8. react native where is apk
  9. react native where to start
  10. react native what is redux
  11. react native what is props
  12. react native what is state
  13. react native what is ref
  14. react native what is a component
  15. react native where to call api
  16. react native what is promise
  17. react native what is eject
  18. react native what is await
  19. react-native what is constructor
  20. react-native what is flexbox

var a = document.createElement('a'); a.setAttribute('target','_blank'); a.click(); The above code doesn't work for me. Does setAttribute not work if the click event happens in JavaScript?

var a = document.createElement('a'); a.setAttribute('target','_blank'); a.click(); The above code doesn't work for me. Does setAttribute not work if the click event happens in JavaScript?

  1. setattribute('target' '_blank')
  2. setattribute target _blank
  3. javascript setattribute target _blank
  4. form.setattribute( target _blank )
  5. link.setattribute('target' '_blank')
  6. js setattribute target _blank