how can I set the .attr() of my iframe by using the variable attrs made below ?
iosocket.on('content', function (object) {
var attrs = '';
for (var key in object) {
attrs = attrs.concat(",'" + key + "':'" + object[key] + "'");
}
attrs = '{' + attrs.substring(1) + '}';
console.log(attrs);
var i = $('<iframe></iframe').attr(attrs);
$('#in').append(i);
});
the console.log say it right but it doesn’t work, my iframe never get the attrs and no error is dropped.
{'width':'853','height':'480','src':'https://www.youtube-nocookie.com/embed/qNaknTgIbIg?rel=0','frameborder':'0','allowfullscreen':''}
I’ve also try with .attr(eval(attrs)), same issue.
The
.attr()function when used as a setter accepts an Object among other alternatives. But,attrsis a String and in that case It will react as a getter not as a setter.I suspect that you need to pass the information as you are receiving it.