简体   繁体   中英

Javascript issue. Receive object HTMLinputelement error

I was trying to copy RSS feed from Reddit site, and use below code, but received HTMLInputElement error. I am not sure if my var function is correct to get content. Please help. Thank you!

<html>
<body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <h1>Get Reddit Keyword RSS Feed</h1>
    <input id="keyword" placeholder="Reddit Keyword">
    <button id="submit">Get Reddit RSS Feed</button>
    <a href="#" style="margin-top: 3rem; display: block;" id="output"></a>
    <script type="text/javascript"> 
        $('#submit').click(function() {
    if ($('#keyword').val() != '') {
    alert('For demonstration purposes only. Please do not point your RSS reader to this server.');
    var keyword = $('#keyword').val();

      $('#output').html('').append('http://www.reddit.com/r/' + $('#keyword').val()) '/.rss').attr('href', 'http://www.reddit.com/r/' + $('#keyword').val()) '/.rss');
    }
  });
</script>

</body>
</html>

I think issue is with your code,

at line

$('#output').html('').append('http://www.reddit.com/r/' + $('#keyword').val()) '/.rss').attr('href', 'http://www.reddit.com/r/' + $('#keyword').val()) '/.rss');

There is syntax error, brackets are not getting closed at right places.

 $('#output').html('')
      .append('http://www.reddit.com/r/' + $('#keyword').val()+ '/.rss')
      .attr('href', 'http://www.reddit.com/r/' + $('#keyword').val() + '/.rss');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM