How to decode html entities, I am unable to do so? - html

here is my codepen https://codepen.io/syedsadiqali/full/BwaMEW.
I'm trying to make a Wikipedia viewer project by freecodecamp. everything is working good except I the snippets from the Wikipedia API, the html entities can't be decoded and span tags can't be replaced. I tried many things. help needed, please.
HTML
<div class="container">
<div class="row row1">
<div class="col-md-6 text-center">
<div class="text-center">
<h2 class="text-center">Welcome to <h2><h1><br> Wikipedia Viewer Project <br> </h1><h2>Search Something Random<br>or<br> Enter Value below.</h2>
</div>
<input type="text" id="querybox">
<div>
<button class="btn btn-primary" id="querybutton">Search</button>
<div>
<a class="btn btn-primary" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">Open Random Page</a>
</div>
<div class="data" id="put"></div>
</div>
</div>
<div class="col-md-6">
<div id="target" class="list-group"></div>
<script type="x-tmpl-mustache" id="template">
{{#search}}<h4 class="list-group-item-heading">{{title}}</h4><p class="list-group-item-text">{{{snippet}}}</p>{{/search}}
</script>
</div>
</div>
<div class="row">
</div>
<footer>
<h3 class='text-center'>Made with love by Syed Source Code would be soon available to you on my Github</h3>
</footer>
</div>
CSS
#import url('https://fonts.googleapis.com/css?family=Pacifico');
.row1{
font-family:"Pacifico",sans-serif;
}
.btn{
margin-top:10px;
padding:20px;
font-size:30px;
}
.row{
margin-top:20px;
}
input{
font-family:sans-serif!important;
}
JavaScript
$("#querybutton").on("click",function(){
data=document.getElementById("put"); query=document.getElementById("querybox").value;
url="https://wikipedia.org/w/api.php?action=query&format=json&prop=&list=search&srsearch=" + query + "&callback=?";
$.getJSON(url,function(json){
var view=json.query;
var template = document.getElementById('template').innerHTML;
Mustache.parse(template);
// render the data into the template
var rendered = Mustache.render(template,view);
//Overwrite the contents of #target with the rendered HTML
document.getElementById('target').innerHTML = rendered;
});
});
Result
https://codepen.io/syedsadiqali/full/BwaMEW

as #Paul Abbott commented I needed to use {{{snippet}}} triple mustache to render the data from Object as HTML. thanks for the answer, this answer I'm just writing to close this Question Right Answer was given by #PaulAbbott. thanks again.

Related

JQuery for multiple div id's that are the same

I have multiple divs with id='title'.
When that div is hovered over I want a hidden div with id="source" to appear.
I am using the following code but only the first div with id='title' on the page works.
<!-- Show Source / Date on mouse hover -->
<script>
$(document).ready(function(){
$("#title").mouseenter(function(){
$("#source").fadeIn( 200 );
});
$("#title").mouseleave(function(){
$("#source").fadeOut( 200 );
});
});
</script>
HTML Example:
<div id="title" class="col-md-3">
<div id="source" style="display:none">Hidden Text</div>
</div>
<div id="title" class="col-md-3">
<div id="source" style="display:none">Hidden Text</div>
</div>
<div id="title" class="col-md-3">
<div id="source" style="display:none">Hidden Text</div>
</div>
Use classes instead of IDs
use .find() to search for descendants of an element
jQuery(function($) { // DOM ready and $ alias in scope
$(".title").on({
mouseenter() {
$(this).find(".source").fadeIn(200);
},
mouseleave() {
$(this).find(".source").fadeOut(200);
}
});
});
.title {
display: flex;
}
/* Utility classe */
.u-none {
display: none;
}
<div class="title col-md-3">
TITLE 1
<div class="source u-none">Visible Text</div>
</div>
<div class="title col-md-3">
TITLE 2
<div class="source u-none">Hidden Text</div>
</div>
<div class="title col-md-3">
TITLE 3
<div class="source u-none">Hidden Text</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Hello Δce Let's start by modifying the source code to use classes for you to pick. This helps us describe the functionality and allow the ID's to serve their purpose.
we'll take your
<div class="col-md-3 show-source-on-hover">
<div class="source" style="display:none">Hidden Text</div>
</div>
<div class="col-md-3 show-source-on-hover">
<div class="source" style="display:none">Hidden Text</div>
</div>
<div class="col-md-3 show-source-on-hover">
<div class="source" style="display:none">Hidden Text</div>
</div>
and we can update the jQuery code
<script>
$(function() {
$(".show-source-on-hover")
.mouseenter(function() {
$(this).find('.source').fadeIn( 200 );
})
.mouseleave(function() {
$(this).find('.source').fadeOut( 200 );
});
});
</script>
You can see here there's the use of this wrapped in the $() jquery object function. and the new use of .find to get get the correct source class.
For a working demo please see the following link: https://codepen.io/jessycormier/pen/GRmaaEb
Note: your use of ID's should change and always try and be unique like others have suggested. MDN (Mozilla Developer Network) has some great documentation on the standards of HTML, CSS, and JavaScript which can help give you.
Also, in the demo I've given your column divs some default size otherwise there is nothing to trigger the mouse over events. Good luck and happy coding 🚀
IDs are IDENTIFIERS. What that means is that there can only be one per document. Classes are not unique, so you can use them.
✅ $(".title")
❌ $("#title")

I have three same Id's in my HTML document and how can I catch the third Id with CSS

I have an HTML document as below :
<!DOCTYPE html>
<html>
<body>
<div id="Caption_G" class="editor-group">
editor-group<br />
<div id="Caption_L" class="editor-label ">
editor-label
</div>
<div id="Caption_F" class="editor-field ">
editor-field
</div>
</div>
<div id="Caption_G" class="editor-group">
editor-group<br />
<div id="Caption_L" class="editor-label ">
editor-label
</div>
<div id="Caption_F" class="editor-field ">
editor-field
</div>
</div>
<div id="Caption_G" class="editor-group">
editor-group<br />
<div id="Caption_L" class="editor-label ">
editor-label
</div>
<div id="Caption_F" class="editor-field ">
editor-field
</div>
</div>
</body>
</html>
How can I catch only third id="Caption_F" with CSS for giving style to this?!
Any help will be appriciated!
Id is supposed to be used only once. If you have multiple instances use a class. With class, you can use
classname:last-child {
//Your styling here
}
For additional info, check this site:
https://www.w3schools.com/cssref/css_selectors.asp
You can put multiple classes in one HTML tag. For example:<div class="editor-label Caption_L></div>
You shouldn't use the same ID more than once. ID must be unique. It is best to use class for similar items that you have already used. With your editor-group class you can use :nth-child() selector.
editor-group:nth-child(3){
//your style
}
First, IDs should be unique. You should edit your document accordingly.
Concerning your problem, you can use :last-of-type:
.editor-group:last-of-type {
// apply styles here
}

Link to same page using div class

I am posting the code. In the line <div class='qrcode-value'></div> it will scan the qr code and I want to make it as link so that it will redirect to the other website once clicking on it. Instead of copy and paste.
<div id="content-overlay" style='display: none'>
<div class='qrcode-value'>
</div>
</div>
<a href="http://google.com">
<div class='qrcode-value'>
anything
</div>
</a>
fiddle https://jsfiddle.net/athulmathew/r73pn4w8/2/
You can use JavaScript to do this.
<div id="content-overlay" style='display: none'>
<div class='qrcode-value' onclick="location.href = 'https://stackoverflow.com/questions/56946816/link-to-same-page-using-div-class';">
</div>
</div>
Read more about onclick event here.

Conversion of HTML to Jade

How do I to write HTML code in Jade?
<div class="profile-env">
<section class="profile-info-tabs">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary" data-collapsed="0">
`enter code here`
<div class="panel-body">
<h2>University Admins <span><a href="add-admin.html" class="btn btn-default pull-right">
<i class="entypo-user-add"></i>
ADD Admin
</a></span>
</h2>
<br />
</div>
</div>
</div>
</div>
</section>
</div>
Please help me before I throw this computer out of the window.
You can use a online conversor like this: http://html2jade.org/
I believe it's called pug now, check this out for some basics;
https://codeburst.io/getting-started-with-pug-template-engine-e49cfa291e33
.profile-env
section.profile-info-tabs
.row
.col-md-12
.panel.panel-primary(data-collapsed='0')
| `enter code here`
.panel-body
h2
| University Admins
span
a.btn.btn-default.pull-right(href='add-admin.html')
i.entypo-user-add
| ADD Admin
br

how to override nokia basic searchbox input style?

I am trying the basic searchbox feature on the API doc http://api.maps.nokia.com/places/BasicSearchBoxExample.html
The HERE api searchbox is too short, I would like to style it.
Here is my html
<div id="container">
<div id="basicSearchBox"></div>
</div>
I don't have access to the below html section (it was generated by the reference in the header <script src="http://api.maps.nokia.com/places/beta3/jsPlacesAPI.js"></script> )
How do I style the input box 'nokia-searchbox-input' to increase the height?
<div id="container">
<div id="basicSearchBox" class="nokia-places-general-searchbox">
<div class="nokia-searchbox">
<input class="nokia-searchbox-input" type="text" rel="searchbox-input">
<input class="nokia-searchbox-button" type="button" rel="searchbox-button" value="Search">
<div rel="searchbox-list" class="nokia-searchbox-list" style="display: none;">
<div class="nokia-searchbox-list-border"></div>
<dl class="suggest-current"></dl>
<dl class="suggest-saved"></dl>
<dl class="suggest-nokia"></dl>
<dl class="suggest-search"></dl>
</div>
</div>
</div>
</div>
Let me know if I'm misunderstanding, but you should be able to just add this to your CSS:
.nokia-places-general-searchbox .nokia-searchbox-input {
height: 20px; /* whatever you want the height to be */
}