user2035638
user2035638

Reputation: 283

jQuery load only certain div content, not parent divs

<div id="value">
 10.00

  <div id="text">hello!</div>
</div>



<script>
setInterval(function(){
    $("#value").load("value.php #value");
}, 5000);
</script>

This is my content of my file.

How do i prevent script loading <div id="text"> too?

Upvotes: 2

Views: 3970

Answers (3)

j08691
j08691

Reputation: 207919

You can use load and then using load's callback, simply remove the div you don't need. Note that you should try to avoid using repeat IDs as it looks like the div you're loading into has an ID of value and the file you're loading from also has an Id of value.

$('#value').load("value.php #value", function () {
    $('#text').remove();
});

jsFiddle example (note that this example uses jsFiddle's AJAX echo API to simulate the call).

Upvotes: 1

Jai
Jai

Reputation: 74738

As i understood your question, you want to load content from #value div from value.php page and you don't want this <div id="text">:

setInterval(function(){
    var content = $("<span id='content'/>").load("value.php #value");
    $('#value').html(content);
}, 5000);

Upvotes: 0

AlecTMH
AlecTMH

Reputation: 2725

You can't prevent that because load gets whole file.

You can use ajax function instead, load the data, manipulate the string then put it into the div.

Or remove the child element after the load is complete:

<script>
setInterval(function(){
    $("#value").load(
         "value.php", 
         function() {
            $('#text').remove();
         }
    );
}, 5000);
</script>

Upvotes: 0

Related Questions