-2

I have some string stored in a JavaScript variable e.g.

var content= '<div id="report" style="display: none;">some content....</div>';

How to set property of this div to display: block; using jQuery?

Syed
  • 891
  • 2
  • 8
  • 29
  • if you just want to change value of display use this command *content.replace('none','block')* but if you want to write it in better way follow this https://stackoverflow.com/questions/3582619/how-to-change-css-display-none-or-block-property-using-jquery – Hamid Shoja Jan 26 '20 at 11:50
  • 2
    This is not "*a div stored in a JavaScript variable*"! This is a String. – leonheess Jan 26 '20 at 11:56

1 Answers1

0

You can try with jQuery's .parseHTML() and .css():

var content= '<div id="report" style="display: none;">some content....</div>';
content = $($.parseHTML(content)).css('display', 'block');
console.log(content[0]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Mamun
  • 66,969
  • 9
  • 47
  • 59