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

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');

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";

How do we change class name from script [duplicate]

This question already has answers here:
How can I change an element's class with JavaScript?
(33 answers)
Closed 2 years ago.
Hello is there any way to edit html tag class name from script?
For example:
html:
<div id="ThisIsId" class= "ThisIsName"> ... </div>
Script:
<script>
document.getElementById("ThisIsId").changeClassName("thisIsNewClassName")
</script>
<script>
document.getElementById("ThisIsId").classList.remove("ThisIsName").add("thisIsNewClassName")
</script>

Detect Element's Children as Numeric Value [duplicate]

This question already has answers here:
JQuery: How to find out how many children an element has?
(2 answers)
Closed 8 years ago.
Fiddle: http://liveweave.com/Aq56fN
In my fiddle I have a div that has a few elements as it's children. Is there anyway to detect how many children an element has as a numeric value? If so how would something like this be done?
JavaScript/JQuery:
$(".grab-contenu").on('click', function() {
$(".spectacle-contenu").html(
$(".contenu").children().toString()
);
});
HTML:
<div class="contenu" align="center">
<header class="largeur-objet">My width is 80%</header>
<button class="grab-contenu">Detect children number</button>
<footer class="spectacle-contenu">Show children number</footer>
</div>
Any help is greatly appreciated.
Try changing
$(".contenu").children().toString()
To
$(".contenu").children().length

get element by javascript [duplicate]

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

number of elements inside a div with jquery [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
get the elements number inside parent div jquery
Is it possible to get the number of elements that are inside a div?
<div id=count">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
the resut should be
4
$('#count').children().length; // 4
var count = $('#count > *').length;

Categories

Resources