2

I wish to populate html input boxes with the data-id from certain elements.

<h2 class="postItem" data-id="23" href="#"></h2>

This an example of a H2 element I have in my site, what I wish to do is take this data-id and place it in a input box.

I am using JavaScript/MooTools to grab the data-ids see this Fiddle

$$('.postItem').addEvent('click', function(e){
var el = e.target;
var id = el.getAttribute('data-id');
alert(id);
});

So my question is how do I then take this data-id and place it inside of a input box?

1 Answer 1

1

I think you mean this.

Just one simple line:

$('melp').value = id;

With melp of course being the id of the input element.

Sign up to request clarification or add additional context in comments.

1 Comment

That's Mootools in a nutshell - simple (yes I'm a professional JQuery-hater ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.