views:

138

answers:

2

I know this has been asked plenty of times before and I already went through a bunch of posts as well as googled for the answer but I just can't figure it out... here's my php

$connect = mysql_connect("localhost", $usuario, $password) or die(mysql_error());
$select_db = mysql_select_db($dbname) or die(mysql_error());

  //query the database
  $query = mysql_query("SELECT css_id, body FROM content");

    //loop through and return results
  for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) {
    $row = mysql_fetch_assoc($query);
    $body[$x] = array("cssID" => $row["css_id"], "inlineContent" => $row["body"]);   
  }

  //echo JSON to page
  $response = $_GET["jsoncallback"] . "(" . json_encode($body) . ")";
  echo $response;

my HTML:

<body>
<h2 class="inlineEdit" id="titulo">Editando</h2>
<div id="response"></div>
<ul>
  <li class="inlineEdit" id="linea">Lorem Ipsum....</li>
</ul>
</body>

and finally my jQuery:

$(function () {
    var domID = [];
    $(".inlineEdit").each(function(){ 
     domID.push(this.id);
    });

    $.getJSON("assets/php/load.php?jsoncallback=?", checkArray);

    function checkArray(data){
     for (var x = 0; x < data.length; x++){//loop through all items in the JSON array
      for(var j = 0; j < domID.length; j++){//loop through the DOM id's array
       if(domID[j] === data[x].cssID){
        var Element = "$('#" + domID[j] + "')";
        Element.text(data[x].inlineContent);
       }
      }
     }
    }
});

I've checked this using firebug and I know for sure that Element equals $('#linea') and data[x].inlineContent contains the correct data but I keep getting the same:

Element.text is not a function

message...

+3  A: 

Should be:

var Element = $("#" + domID[j]);

else Element is a string.

o.k.w
thanks can't believe I didn't see that...
Luis Armando
@Proxify: It's a typical developer's 'blackhole'. Sometimes you just need to bounce it off someone or in SO :P
o.k.w
A: 
var Element = "$('#" + domID[j] + "')";

assigns a string to variable Element which don't have a text function. Also a syntax error. Thanks @o.k.w for pointing this out.

var Element = $('#' + domID[j] );

assigns jQuery object to variable Element

rahul
@adamantium: No prob. I've neutralised your down-vote already. It wasn't me ok :P
o.k.w