0

In this case I am not able to escape the quotes I think.

I am trying this from last one day

var obj = deals[i]; 
var1 = "my var"
var url =  "index.html?name="+obj['a']+"&user="+var1+"+obj['a'];

var div = document.createElement('div');
div.innerHTML = '<div style="width: 100%; overflow: hidden" >' +
'<div style="width: 10%; float: left;" >' +
'<div><img src="assets/img/userimg.png" style="height: 35;margin-left: 10; margin-right: 5px;"/></div> <div id="toro" style="color: black">' +  obj['a'] + '</div>' +
 '</div>' +
 '<div style="margin-left: 25%;">' +
 '<div style="margin-top: 7;font-weight: bold; color: black">' +obj['b']+'</div> <div style="color: black" >' + '</div><div style="float: right" id="time">'+'</div></div></div> '+'<hr class=\"hr-clas-low\" />';

  document.getElementById('deals').appendChild(div)

How do I add the url as onclick href url to the newly created div?

OK I am rewriting this question again to convey where I am stuck exactly

var obj = deals[i]; 
var1 = "my var"
 var url =  "index.html?name="+obj['a']+"&user="+var1+"+obj['a'];




var div = document.createElement('div');
div.innerHTML = '<div style="width: 100%; overflow: hidden"    onclick="location.href='+url+'>' +
'<div style="width: 10%; float: left;" >' +
'<div><img src="assets/img/userimg.png" style="height: 35;margin-left:    10; margin-right: 5px;"/></div> <div id="toro" style="color: black">' +        obj['a'] + '</div>' +
'</div>' +
'<div style="margin-left: 25%;">' +
'<div style="margin-top: 7;font-weight: bold; color: black">'       +obj['b']+'</div> <div style="color: black" >' + '</div><div style="float:       right" id="time">'+'</div></div></div> '+'<hr class=\"hr-clas-low\" />';

document.getElementById('deals').appendChild(div)

I have added onclick="location.href='+url+' to the external div but its not working?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ritzor
  • 665
  • 7
  • 26

1 Answers1

0

The only error i see in this code is in the three first lines:

var obj = deals[i]; 
var1 = "my var"
 var url =  "index.html?name="+obj['a']+"&user="+var1+"+obj['a'];

I think it should be:

var obj = deals[i]; 
var1 = "my var";
var url =  "index.html?name="+obj['a']+"&user="+var1+obj['a'];

Then:

div.innerHTML = '<div style="width: 100%; overflow: hidden" onclick="location.href='+url+'"><div style="width: 10%; float: left;" ><div><img src="assets/img/userimg.png" style="height: 35;margin-left: 10; margin-right: 5px;"/></div><div id="toro" style="color: black">'+obj['a']'+</div></div><div style="margin-left: 25%;"><div style="margin-top: 7;font-weight: bold; color: black">'+obj['b']+'</div><div style="color: black" ></div><div style="float: right" id="time"></div></div></div><hr class="hr-clas-low" />'

Should work just fine

Kevin Chacón
  • 175
  • 12