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
Member Avatar for LastMitch

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.

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

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);
Member Avatar for LastMitch

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.

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.