I
I
ilyasmirnov2017-09-28 17:00:36
JavaScript
ilyasmirnov, 2017-09-28 17:00:36

How to pass text from div to value?

Oddly enough, this question is not even on the Internet.
There are divs with class "name" and input with id:nama
How to pass text from div to value "value"?
In the block, the text is substituted only when the page is loaded using php, but in the input it can be conditionally passed only using jQuery.
I understand that the question is in one line of code, but somehow I can’t “make friends” with this question myself

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
i1yas, 2019-06-18
@senchkim

return (sum + item.weight, 0);
You had an error in reduce, because of this, 0 was always returned. The start value must be passed after the callback function. This is first.
This condition matches filter

const arrayWeight = myArray.filter(item => item.type !== 'car').reduce((sum, item) => {
  return sum + item.weight
}, 0);

A
Anton Fedoryan, 2019-06-18
@AnnTHony

https://jsfiddle.net/uxjyeshv/

D
Danakt Frost, 2017-09-28
@ilyasmirnov

var text = $('.name').text()
$('#nama').val(text)

S
Salim_Gareev, 2017-09-28
@Salim_Gareev

I would give the div an id instead of a class.

var text = $('#div').text();
$('#input').val(text);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question