S
S
sanekstr2015-10-07 01:24:11
JavaScript
sanekstr, 2015-10-07 01:24:11

How to add a link to a div using javascript?

Hello, please help, how to ... add a link "" via javascript?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergeyj, 2015-10-07
@sanekstr

<div id="myLink">тут будет ссылка</div>
<script type="text/javascript">
    var div = document.getElementById('myLink');
    var e    = document.createElement('a');
    e.href = 'http://google.ru';
    e.title = 'это ссылка';
    e.appendChild(document.createTextNode('ссылка'));
    div.appendChild(e);
</script>

or with jquery
$("#myLink").html('<a href="http://google.ru">ссылка</a>')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question