0

Hello. i load data from a data.json file. each div named content shows contetn[i] from the json file. but i dont want all of this to be shown. i want only the the hovered div to be shown.but this code doesnt work.any help ?

$.getJSON('data.json', function(data) {
for (var i=0;i<18;i++) {
var content=<div id=\"content\">"+data[i].content+"</div>"
         $("#news").append(content);

         $("#content").hide();
         $("#content").hover(function(){
        $("#content").show();},
        function(){
           $("#content").hide(); 
        } );//end hover
            }//end for
            });//end json
3
Contributors
5
Replies
39
Views
4 Years
Discussion Span
Last Post by minitauros
1

but this code doesnt work.any help ?

The code is a bit messy.

What was the code before you modify it. Can you post the original code. So we can have a better idea what your doing.

I can't even test the code either.

1

Well for starters, there appears to be missing a " at the start of your content definition (content=<div id=\"content\">) :).

0

I want to display only some data from the .json file. when i select UK it displays some data. when i reselect it, it reposts the same data after it.when i select US the old data are still there, and the new one are poster.
what i want to do is that: if i select UK:it should display ab,cd for example. and when i select US it should clear the precious post and post de,ef for example.any help?
and thx for replying

    <div id="prova">
    </div>
<p id="para"></p>
<select id="state">
<option>US</option>
<option>UK</option>
</select>

function displayVals() {
 $.getJSON('data.json', function(data) {
var singleValues = $("#state").val();
$("#para").html(singleValues);
       for (var i=0;i<5;i++) {
        if (singleValues==data[i].country) {        
        var ndr=data[i].title+"<br><hr>"
       $("#prova").append(ndr);    
    }
    }
      });   
}
displayVals();
$("select").change(displayVals);
0

I want to display only some data from the .json file. when i select UK it displays some data. when i reselect it, it reposts the same data after it.when i select US the old data are still there, and the new one are poster.

What is the data? Is it in an array or from your database.

0

Instead of using the append() function you could use the html() function. It clears the target node from any content it has and puts the content you provided into it. E.g. $('#prova').html(ndr) instead of $('#prova').append(ndr).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.