1

I create the variable for event link, as the user input the link, I want it to display as a hyperlink in HTML by using jquery. Since user could do a infinite input, therefore the output of the link will be on the next line.

var $event_link_selector = $('#event-link');
var event_link = $event_link_selector.val();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="event-link">Event Link:</label>
<textarea id="event-link"></textarea>

Ex: If the user enters www.example.com into the test area, I want the page to return me that link and be able to click on it. These are the jquery I currently trying but not working

//returns me the user input link as string instead of link
"<br> <a class='event-description'>"+ event.event_link + "</a>"

//returns none
"<br> <a class='event-description' href='" + event.event_link + "'></a>"

1 Answer 1

2

You didn't share your whole jQuery code... But it's already clear your quotes were misplaced!

$('#event-link').on('focusout',function(){
  var event_link=$(this).val();
  $(this).parent('.link-container').append('<a class="event-description" href="' + event_link + '">'+event_link+'</a>');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="link-container">
<label for="event-link">Event Link:</label>
<textarea id="event-link"></textarea>
</div>

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

2 Comments

Thank you so much, now it works, and my code turns to be '<br> <a class="event-link" href="' + event.event_link + '">'+ event.event_link+'</a>' I saw the cases where I did it wrong, I didn't display the link to HTML all all
You are welcome! You can set it as an accepted answer if your problem is solved..

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.