JavaScript Conditionally append elements from parsed JSON that match a value

I'm looking to append elements conditionally to a container based on whether the tags data matches the key variable.

The way tags' data is returned is like tag1 tag2 tag3 tag4 tag5, the key is matching some of the tags data but it still isn't doing the conditional append.

Any kind of help with this headache would be greatly appreciated!

Here's the code:

var key = getParameterByName('img');

var tags = item.tags;

        if (key != null){
          //move onto conditional append

          if (key === tags) {

        $('<div class="photo">
           <figure class="cell" data="'+tags+'">
           <figcaption class="caption" style="display: none;"> '+title+' <a target='_blank' href="">click</a></figcaption>
           <a target='_blank' href="' +imgb+ '"><img src="' +img+ '" class="small-image"/></a></figure>').appendTo('#container');
          }
        }
        else {
        $('<div class="photo"><figure class="cell" data="'+tags+'"><figcaption class="caption" style="display: none;">'+title+'<a target='_blank' href="">click</a></figcaption><a target='_blank' href="'+imgb+'"><img src="'+img+'" class="small-image"/></a></figure>').appendTo('#container');
      }
Answer:1

Try (tags.includes(key)) instead of (key === tags). You are checking if a string is included in a larger string, not if "tag1 tag2 tag3" is exactly equal to "tag1."

Answer:2

I'd like to track a form on my real-estate website. The difficulty is that I have 3 radio buttons (only one can be chosen) and I don't know how to link the button chosen to the event that will be send ...

I'd like to track a form on my real-estate website. The difficulty is that I have 3 radio buttons (only one can be chosen) and I don't know how to link the button chosen to the event that will be send ...

  1. google analytics event tracking
  2. google analytics event category
  3. google analytics event value
  4. google analytics event tracking examples
  5. google analytics event goals
  6. google analytics event funnel
  7. google analytics event flow
  8. google analytics event types
  9. google analytics event tag
  10. google analytics event timestamp
  11. google analytics event category examples
  12. google analytics event limits
  13. google analytics event setup
  14. google analytics event value string
  15. google analytics event custom dimension
  16. google analytics event label not set
  17. google analytics event count
  18. google analytics event label character limit
  19. google analytics event code generator
  20. google analytics event tracking gtag

I have several components that use basically the same table so I'm in the process of abstracting out that table. I have solved most of my dynamic table population needs but have yet to find a solution ...

I have several components that use basically the same table so I'm in the process of abstracting out that table. I have solved most of my dynamic table population needs but have yet to find a solution ...

  1. angular passing click event

I'm getting an unusual error: ctx_wrap.fillStyle is not a function on this line: ctx_wrap.fillStyle('#b8b8b8'); in here: ... this.paint = function() { self.path(ctx_wrap); if (!isOver) {...

I'm getting an unusual error: ctx_wrap.fillStyle is not a function on this line: ctx_wrap.fillStyle('#b8b8b8'); in here: ... this.paint = function() { self.path(ctx_wrap); if (!isOver) {...

What happens when you do npm install in a dev environment on a project that has both a package.json and a npm-shrinkwrap.json file? Will it ignore the shrinkwrap and use package.json for everything or ...

What happens when you do npm install in a dev environment on a project that has both a package.json and a npm-shrinkwrap.json file? Will it ignore the shrinkwrap and use package.json for everything or ...

  1. shrinkwrap developmental psychology with connect