You could decide to make use of a templating engine in your project, such as:
If you don’t want to include another library, John Resig offers a jQuery solution, similar to the one below.
Browsers and screen readers ignore unrecognized script types:
<script id="hidden-template" type="text/x-custom-template"> <tr> <td>Foo</td> <td>Bar</td> <tr> </script>
Using jQuery, adding rows based on the template would resemble:
var template = $('#hidden-template').html(); $('button.addRow').click(function() { $('#targetTable').append(template); });
Related Posts:
- Nested JSON objects – do I have to use arrays for everything?
- Uncaught TypeError: Cannot read property ‘length’ of undefined
- Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js
- jQuery AJAX cross domain
- Loading local JSON file
- Uncaught TypeError: data.push is not a function
- How to convert selected HTML to Json?
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- How to display raw JSON data on a HTML page
- Convert array to JSON
- How to filter JSON Data in JavaScript or jQuery?
- How to add a button dynamically using jquery
- Complex JSON nesting of objects and arrays
- Uncaught SyntaxError: Unexpected token with JSON.parse
- How can JavaScript save to a local file?
- Remove escape characters from JSON string pulled from a database
- What is JSONP, and why was it created?
- Cannot read property ‘push’ of undefined when combining arrays
- Chrome sendrequest error: TypeError: Converting circular structure to JSON
- How to deal with net::ERR_SSL_PROTOCOL_ERROR?
- How to read an external local JSON file in JavaScript?
- SyntaxError: Unexpected token o in JSON at position 1
- Check if checkbox is checked with jQuery
- Getting Error “Form submission canceled because the form is not connected”
- Is there a link to the “latest” jQuery library on Google APIs?
- What is the “right” JSON date format?
- How can jQuery deferred be used?
- Uncaught TypeError : cannot read property ‘replace’ of undefined In Grid
- Disable/enable an input with jQuery?
- Get class name using jQuery
- What does on() in JavaScript do?
- jQuery animate backgroundColor
- Use images like checkboxes
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- ChangeDate – Date Picker Bootstrap
- Uncaught TypeError: Cannot read property ‘msie’ of undefined
- How to hide a div with jQuery?v
- How do I set/unset a cookie with jQuery?
- Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
- How to update array value javascript?
- How to move an element after another element using JS or jquery?
- Why is the jquery script not working?
- JQuery Datatables : Cannot read property ‘aDataSort’ of undefined
- TypeError: $(…).DataTable is not a function
- jQuery explode string like PHP
- Validate date in dd/mm/yyyy format using JQuery Validate
- Simulate Keypress With jQuery
- react router v^4.0.0 Uncaught TypeError: Cannot read property ‘location’ of undefined
- Adding options to a
- Refused to execute script, strict MIME type checking is enabled?
- jQuery Ajax POST example with PHP
- Setting and getting localStorage with jQuery
- How to get current date in jQuery?
- Print the contents of a DIV
- How to Scroll Down – JQuery
- Embedding instagram webpage inside an iframe
- Do something if screen width is less than 960 px
- Javascript isnull
- Set value to currency in
- HTML Entity Decode
- jquery beforeunload when closing (not leaving) the page?
- How do I pass the this context to a function?
- JSON.parse unexpected token s
- Escaping HTML strings with jQuery
- is there something like isset of php in javascript/jQuery?
- jQuery – Dynamically Create Button and Attach Event Handler
- How to use z-index in svg elements?
- What is the best way to detect a mobile device?
- Highlight a word with jQuery
- Get querystring from URL using jQuery [duplicate]
- jQuery checkbox change and click event
- jQuery selectors on custom data attributes using HTML5
- How do I refresh a DIV content?
- TypeError: abc.getAttribute is not a function
- jQuery sort elements using data id
- How to fire an event on class change using jQuery?
- How to open a Bootstrap modal window using jQuery?
- window.location.replace() not working to redirect browser
- How should I initialize jQuery?
- How to reload page every 5 seconds?
- How do I handle newlines in JSON?
- jquery to validate phone number
- Closing Bootstrap modal onclick
- Fire oninput event with jQuery
- “NS_ERROR_DOM_BAD_URI: Access to restricted URI denied”
- How to set “style=display:none;” using jQuery’s attr method?
- How to dequeue a script?
- How to use wp_localize_script in custom page template?
- Dynamically insert values in a WordPress SelectControl Options field
- AngularJS with route and JSON API
- List of JS Events for Widgets?
- Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]
- Parse wordpress blog data using json api and ajax
- Putting custom html/js page into Elementor as it’s own block
- Get the ID of a page in Parent combobox in editor
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- Open image gallery on link click
- Styling parent based on a child element of a child in a WordPress page
- Gutenberg core/file add style support in js/ json