views:

34

answers:

4

Hello,

I am trying get the html within .event_recur.

$(".entry").each(function(){
alert($(this).find(".event_recur").html());
});


<div class="entry">
<p class="event_title">June 21st Event - eat</p>

<p class="event_start_date">1277160289</p>
<p class="event_end_date">1277505889</p>
<p class="event_body"><p>June 21-25th
</p></p>
<p class="event_recur"><p>No
</p></p>
<p class="event_body"><p>June 21-25th
</p></p>

<p class="event_location"><p>Pac Sun
</p></p>
<p class="event_categories">
Eat
</p>

</div>

I get nothing when I do:

$(".entry").each(function(){
    alert($(this).find(".event_recur").html();
});

I was expecting:

<p>No
    </p>

Am I missing something? Thanks!

+1  A: 

you are missing an document ready closure; i.e. change the invocation to:

$(function(){
  $(".entry").each(function(){
    alert($(this).find(".event_recur").html());
  });
});

(FYI, $(function(){}); is an alias for $(document).ready(function(){});)

azatoth
Sorry I should of posted. I do have all of this in $(document).ready(function() {code here});
Fostah
+1  A: 

No is not in any paragraph tag right now. It's outside your desired <p class="event_recur">.

hookedonwinter
The doc ready thing the other answers give is also true. Two issues here.
hookedonwinter
<p class="event_recur"><p>No </p></p> ?
Mark Schultheiss
oh. ha. reading is fun! earlier it looks like <p class="event_recur"></p>No<p><p>, but I must have read it wrong.
hookedonwinter
With HTML5 doctype it would strip the nested paragraph tag out when getting the html with .html(). This is why it would come back blank.
Fostah
+1  A: 

Try wrapping your function like so:

$(function () {
  $(".entry").each(function(){
    alert($(this).find(".event_recur").html());
  });
});

That will delay execution until after the DOM is loaded.

g.d.d.c
Hey gddc, I do have this all within $(document).ready(function() {}); If I alert .event_start_date, I get back the value in the html. However it seems since .event_recurring has a p tag it doesn't work :/
Fostah
The presence of a `<p>` tag should not affect jQuery's html() function. In your original post there is a typo in your alert (missing a final closing paren), but if that's in your actual document it should raise an error in a utility like FireBug if you're using anything to track that kind of thing.
g.d.d.c
A: 

So it looks like with HTML5 Doctype: nesting P tags was causing the issue with the selector. I'm not sure if why exactly but I turned .event-recur into a div and it output the html fine! YES!

Note to self: don't nest p tags with HTML5 doctype. I'm not positive its the doctype but maybe someone else can clarify.

Fostah