0

So I have my HTML inside a jquery object and want to grab an element by class from that object, I have the following code:

var feed = data.post.content;
var $newFeed = $(feed);
var stuff = $newFeed('.ERSIngredients').html();
console.log(stuff);

When I print $newFeed itself I can see this div with this class exist, but I'm always getting an error: "Uncaught TypeError: object is not a function"

What am I doing wrong?

2
  • api.jquery.com/filter Commented Mar 19, 2014 at 23:51
  • var stuff = $('<div />', {html : feed}).find('.ERSIngredients').html(); Commented Mar 19, 2014 at 23:53

1 Answer 1

4

I think that you want:

var stuff = $newFeed.find('.ERSIngredients').html();

In other words, find a descendent of $newFeed with the class ERSINgredients and then get the html out of that.

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

2 Comments

OP asked for an element of the jquery object. This gives a descendant of an element of the object. It's possible this is what they meant though.
So right now I'm trying to get every p elements using the same method by I'm always getting an empty variable. var content = ""; $newFeed.find("p").each(function(index, element) { content += $(this).html(); }); Print empty, but if I change it to for example $newFeed.find("div") then I will get every div.

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.