get element by javascript [duplicate] - javascript

This question already has answers here:
PHP DOMDocument getting Attribute of Tag
(2 answers)
Closed 9 years ago.
How can I get the image url which embeded in below media: thumbnail tag ?
<link href="http://example.com" type="text/html">
<media:content>
<media:thumbnail url="http://example2.com/1.jpg" width="150" height="100"></media:thumbnail>
</media:content>
</link>
I am looking for something like
var link = tag.querySelectorAll('link')[0];
var media = link.querySelector('media:content');
var thumbnail= link.querySelector('media:thumbnail');
var url= thumbnail.getAttribute('url');
but obviousely querySelector could not retrieve the value of media:content

Simply to use attr
jsfiddle example

$('media:thumbnail').attr('url');
This may help you

Related

How i can change text in HTML with Javascript [duplicate]

This question already has answers here:
Find and replace specific text characters across a document with JS
(14 answers)
Closed 11 months ago.
<a href="/knowledgebase/category/community?language=tr" class="Category-Item">
<h4><span><i class="fas fa-comments"></i></span> Community</h4>
<p></p>
<span class="MoreArticles">8 Makaleler</span>
</a>
I want find and replace text under a class.
For example; Finding "Community" text and change to "Topluluk".
I writed a javascript language and i need do this for non-multilangual application.
Before:
<a href="blabla" class="**Category-Item**"><i class="blabla">Community</i>
After:
<a href="blabla" class="**Category-Item**"><i class="blabla">Topluluk</i>
from what i understood , you can select the element then change the inner text. if that's not what you ment please leave a comment.
let text = document.querySelector('h4');
text.innerText = "changed";

Javastript syntax in quotes [duplicate]

This question already has answers here:
Template literals like 'some ${string}' or "some ${string}" are not working
(7 answers)
Closed 2 years ago.
I want to use js syntax to have diffrent URL for each image. Robohash website give us random robot image if we use diffrent URL ending, in that way i want to do below, but looks like ${props.id} is not treated as syntax but just as a part of URL, so im gets the same image for all.
<img alt='robots' src={"https://robohash.org/${props.id}"} />
<img alt='robots' src={`https://robohash.org/${props.id}`} />
You should use template string using backticks:
<img alt='robots' src={`https://robohash.org/${props.id}`} />

Replace div with new div using jQuery or javascript [duplicate]

This question already has answers here:
Replace Div with another Div
(3 answers)
Closed 6 years ago.
I need a simple solution for replacing a div with a new div, cross-browser compatible using javascript or JQuery. I'll add some code below. Div "myDiv-B" needs to be replaced by a new div:
<div id="myDiv-C">{% include 'snippets/contactpaneel.rain' %}</div>
Here are my divs
<div id="myDiv-A">
<div id="myDiv-B"></div>
</div>
You should use .replaceWith() method.
.replaceWith method replace each element in the set of matched
elements.
$('#myDiv-B').replaceWith('<div>Hello</div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv-A">
<div id="myDiv-B"></div>
</div>

How to use RegExp to match all characters between HTML tags? [duplicate]

This question already has answers here:
What to do Regular expression pattern doesn't match anywhere in string?
(8 answers)
Closed 8 years ago.
I want to use JavaScript to match ALL content between <div class="class-test"> and </div>. What RegExp should I use?
The complicated part is, there might be some more HTML tags inside it. For example:
<div class="class-test">
<div> this is a sub div </div>
<p>this is a p</p>
</div>
BTW, The HTML is not real HTML but just pure text. So it's not possible to 'parse' it. I am actually using Node.JS to modify a HTML file.
Thanks.
You can do this easily with a module like cheerio:
var cheerio = require('cheerio');
var $ = cheerio.load('<div class="class-test"><div> this is a sub div </div><p>this is a p</p></div>');
var content = $('div.class-test').html();
console.log(content);

How taking the value of a href attr in a div [duplicate]

This question already has answers here:
jQuery: How to get the value of an html attribute?
(6 answers)
Closed 8 years ago.
I have a link, how can i get the value of the alt attr in my href ? (1)
<div class="user_line">
<img class="delete_user" src="images/close_button_mini.gif">
<a class="chat_user" alt="1|Test" href="#">Test</a>
</div>
// With $this
$('.delete_user').live('click',function(){
}
Thanks
you can take the alt like this
var alt=$('.chat_user').attr('alt');

Categories

Resources