user3631192
user3631192

Reputation:

Updating the content of a div using jquery waypoints

I am using waypoints.js

In the HTML given below, when the waypoint of a hardware class is reached it should update the content of the <div> having class number with the content of the div.current within the div.hardware.

My html:

<div class="number"></div>

<div class="hardware">
    <div class="current">1</div>
</div>

<div class="hardware">
    <div class="current">2</div>
</div>

<div class="hardware">
    <div class="current">3</div>
</div>

<div class="hardware">
    <div class="current">4</div>
</div>

I have this:

$(function() {
    $('.hardware').waypoint(function() {
        var addNumber = $(this).find('.current').content();
        $('.number').content(addNumber);
    });
});

but this doesn't work for me.

Upvotes: 0

Views: 309

Answers (1)

T J
T J

Reputation: 43156

The jquery method is contents(), not content()

$(function() {
 $('.hardware').waypoint(function() {
    var addNumber = $(this).find('.current').contents();
    $('.number').contents(addNumber);
 });
});

P.S: contents() method even retrieves comment nodes. For getting the text content from an element, it's better to use text() method.

Upvotes: 0

Related Questions