0

I keep running into this issue and I'm sure there is a way around it.

Currently I am building a website that has many blogs. The blogs have an RSS feed that I can use with a neat little jquery script I found to pull back data from the blog such as the blog title, date of blog, blog image, etc.

The script I'm using uses shortcode to render these attributes for example:

<script type="text/javascript" src="http://cdn2.hubspot.net/hub/213747/file-722482310-js/scripts/jquery.rss.js"></script>
<script type="text/javascript">
  jQuery(function($) {
    $("#tech_feed").rss("http://www.example.com/big-data/rss.xml", {
      limit: 1,
      entryTemplate:  '<h1 id="blog_title">{blog-title}</h1>'
});
</script>

This works great and brings in the title. However I would like to use Jquery to do a substring or slice on this title, but since it is dynamically added I can't seem to grab it. I can do it in the console, but what do I need to do so that I can 'grab it' after it has been loaded as html? Is this possible?

2 Answers 2

1

Looks like the plugin you're using has a callback param. So, you can do:

$(function() {
    $("#tech_feed").rss("http://www.example.com/big-data/rss.xml", {
        limit: 1,
        entryTemplate:  '<h1 id="blog_title">{blog-title}</h1>'
    }, function() {
        //Do your thing here where the feed has been loaded;
        //Such as
        alert ( $("#blog_title").text() );
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

EDIT:

After reading your comment, what you want is to operate in the callback after the data arrives:

$("#tech_feed").rss("http://www.feedforall.com/sample.xml", {
  limit: 1,
  entryTemplate:  '<h1 id="blog_title">{title}</h1>'}, function() {  });

as seen here: http://jsfiddle.net/heavyhorse/rz59L0r2/

if you want to modify the inner html of the element try something like this after the data has arrived:

$('#blog-title').text(newTitleData);

http://jsfiddle.net/heavyhorse/y78phrv5/

1 Comment

Yes, this is what I'm doing in the console. I can't seem to get the after data has arrived part. How can I ensure the data has a arrived? The actual h1 element loads with the rest of the page, and I suspect the data pulled over arrives shortly after.

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.