D
D
Demon2015-10-02 11:54:36
JavaScript
Demon, 2015-10-02 11:54:36

How to get value?

How to receive and pass value ?
An example is html code:

<div class="item" value="800"></div>
<div class="item" value="801"></div>
<div class="item" value="802"></div>
<div class="item" value="803"></div>

There is also a script that receives and passes value
var Vallue = $('#item_answer').attr("value");
$('.item'+Vallue+'').hide();

But the script receives only 1 value 800
How can the script be rewritten so that it receives all the value itself ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-10-02
@In4in

Didn't your mother tell you that you can't set attributes to elements, whatever you like (except perhaps data-what_you like )?

<div class="item" data-value="800"></div>
<div class="item" data-value="801"></div>

<div class="item800"></div>
<div class="item801"></div>

$(".item").each(function(){
  var num = this.dataset.value;
  $('.item'+num).hide();
});

D
Dmitry Kovalsky, 2015-10-02
@dmitryKovalskiy

You have written some heresy.
1) The class is item and the selector is "id= item_answer".
2) Further, in order not to write .attr("value"), you can simply write .val().
3) Vallue - this is a sign that you did not manage to come up with a variable name.
4) $('.item'+Vallue+'') = $(".item801") - do you have such classes? more precisely $(".item[value='+Vallue+']").hide

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question