Skip to content Skip to sidebar Skip to footer

Javascript - Get HTML Attribute Value From A JSON Request

I have a JSON request result for a blogger post. // API callback posts( { 'version': '1.0', 'encoding': 'UTF-8', 'entry': { 'title': { '

Solution 1:

Update

Try this...

function posts(data) {
   var formatData = $(data.entry.content['$t']).data('format');
}

Update #2

In case if your data object, or any of it's properties/subproperties might be not defined, here is safer version:

function posts(data) {
   var formatData = data 
      && data.entry 
      && data.entry.content 
      && data.entry.content['$t'] 
      && $(data.entry.content['$t']).data('format') || '';
   if (formatData!='') { //If has value
      // ... have something to do about it
   } 
}

JSFiddle


Solution 2:

Try this...

$(variable.entry.content['$t']).data('format');

where variable is a parameter of your post method.


Post a Comment for "Javascript - Get HTML Attribute Value From A JSON Request"