Appending HTML code to a div using JS - without double quotes

user2822127

I need to grab each photo from a directory, wrap it in some s and add the whole thing to a container div.

The issue is that in the browser each line shows up inside a set of double quotes.

Here a minimal version of my JS

<script>
var folder = "gallery-all/";
var photosRow = document.getElementById("photo-row");

var prefix = "<img src='";
var postfix = "'>";

$.ajax({
    url : folder,
    success: function (data) {
        $(data).find("a").attr("href", function (i, val) {
            if( val.match(/\.(jpe?g|png|gif)$/) ) { 
                photosRow.append(prefix + folder + val + postfix);
            } 
        });
    }
});
</script>

This is what shows is the browser:

<img src='gallery-all/img1.jpg'>
<img src='gallery-all/img2.jpg'>
<img src='gallery-all/img3.jpg'>
<img src='gallery-all/img4.jpg'>

and upon inspecting the page the code is:

"<img src='gallery-all/img1.jpg'>"
"<img src='gallery-all/img2.jpg'>"
"<img src='gallery-all/img3.jpg'>"
"<img src='gallery-all/img4.jpg'>"

I have tried various methods of escaping, storing different parts as variables, etc. Regardless of what I do, the double quotes always show up.

mwilson

You're only appending the string. You need actually append an element instead.

<script>
var folder = "gallery-all/";
var photosRow = document.getElementById("photo-row");

var prefix = "<img src='";
var postfix = "'>";

$.ajax({
    url : folder,
    success: function (data) {
        $(data).find("a").attr("href", function (i, val) {
            if( val.match(/\.(jpe?g|png|gif)$/) ) {
                const img = $('<img />', { src: folder + val });
                photosRow.append(img);
            } 
        });
    }
});
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Appending multiple HTML elements without using .html

From Dev

Using awk to print without double quotes

From Dev

Appending symbol code to HTML from a JS function

From Dev

Is it possible to add a column and remove double quotes without using a temp file?

From Dev

How to print an empty string without double quotes using awk command

From Dev

Launching powershell script from cmd without using double quotes (")

From Dev

When sending html code through PHP/AJAX it escapes the double quotes

From Dev

CSV replace quotes with their HTML code using regex

From Dev

Appending HTML and PHP code

From Dev

How can I replace two double quotes with one double quotes using Regex without capturing occurrences of one double quote?

From Dev

Enter quotes and double quotes in a html textarea without an insertion operation fail in database. Is it possible?

From Dev

Using double quotes in awk

From Dev

Using double or no quotes with wildcards

From Dev

Appending html to a div using Jquery - add Bootstrap Tooltip to appended items

From Dev

Why appending a div using html and jquery variable has different outputs?

From Dev

How to print specyfic String without using double quotes nor single quotes?

From Dev

this code replacing the html not appending the html

From Dev

Bash, is there a way to get the same function as double quoting a variable without using double quotes

From Dev

Appending new content (HTML) to existing using Vue JS objects

From Dev

C# appending string from variable inside double quotes

From Dev

parse html with single or double quotes

From Dev

how to get tag value without quotes using js regex

From Dev

Escaping double double quotes in html attributes in Javascript

From Dev

.load html code without replacing div

From Dev

How can I print a text in c/c++/java without double quotes and apostrophes in source code

From Dev

using double quotes and if condition in excel

From

export double quotes using template

From Dev

remove double quotes using a macro

From Dev

Using strip() to removed double quotes

Related Related

  1. 1

    Appending multiple HTML elements without using .html

  2. 2

    Using awk to print without double quotes

  3. 3

    Appending symbol code to HTML from a JS function

  4. 4

    Is it possible to add a column and remove double quotes without using a temp file?

  5. 5

    How to print an empty string without double quotes using awk command

  6. 6

    Launching powershell script from cmd without using double quotes (")

  7. 7

    When sending html code through PHP/AJAX it escapes the double quotes

  8. 8

    CSV replace quotes with their HTML code using regex

  9. 9

    Appending HTML and PHP code

  10. 10

    How can I replace two double quotes with one double quotes using Regex without capturing occurrences of one double quote?

  11. 11

    Enter quotes and double quotes in a html textarea without an insertion operation fail in database. Is it possible?

  12. 12

    Using double quotes in awk

  13. 13

    Using double or no quotes with wildcards

  14. 14

    Appending html to a div using Jquery - add Bootstrap Tooltip to appended items

  15. 15

    Why appending a div using html and jquery variable has different outputs?

  16. 16

    How to print specyfic String without using double quotes nor single quotes?

  17. 17

    this code replacing the html not appending the html

  18. 18

    Bash, is there a way to get the same function as double quoting a variable without using double quotes

  19. 19

    Appending new content (HTML) to existing using Vue JS objects

  20. 20

    C# appending string from variable inside double quotes

  21. 21

    parse html with single or double quotes

  22. 22

    how to get tag value without quotes using js regex

  23. 23

    Escaping double double quotes in html attributes in Javascript

  24. 24

    .load html code without replacing div

  25. 25

    How can I print a text in c/c++/java without double quotes and apostrophes in source code

  26. 26

    using double quotes and if condition in excel

  27. 27

    export double quotes using template

  28. 28

    remove double quotes using a macro

  29. 29

    Using strip() to removed double quotes

HotTag

Archive