- Getting the parent span title value from child node using Javascript or jQuery
- Getting the parent span title value from child node using Javascript or jQuery
- Jquery parent’s span
- How do I select a span content, using jquery?
- jQuery get the span title for each language and insert in a new span
- Javascript Source Code
- Related
- jQuery get the span title for each language and insert in a new span (Demo 2)
- Javascript Source Code
- Related
- jQuery Get span title (Demo 2)
- Javascript Source Code
- Related
Getting the parent span title value from child node using Javascript or jQuery
HTML: JS: Thanks Solution 1: The span is a sibling of the anchor, not it’s parent. Altough I dont recommend it, you can fix your issue using the following approach: However, you should avoid attaching event handlers using attributes and use the approach below: Put a class on your tags, like for instance ( you could also use any other shared attributes, if any ).
Getting the parent span title value from child node using Javascript or jQuery
I am reconstructing this question. I have the following HTML element structure.
I want to be able to get title value of with id=editedpart , which is the immediate parent of the tag when the link is clicked. I don’t know how to explain it more. I will appreciate it if someone can help. Thanks.
I used his jQuery code var parent = $(this).closest(«span»);
Here is my full showeditpage()
function showeditpage()< var page = document.getElementById("t_div").value; var action = document.getElementById("edit").title; var parent = $(this).closest("span[id='editedpart']"); var str =parent.attr('title'); if(window.XMLHttpRequest)< xmlhttp = new XMLHttpRequest(); >else < xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); >xmlhttp.onreadystatechange = function() < if(xmlhttp.readyState == 4 && xmlhttp.status == 200)< document.getElementById("pcontent").innerHTML = xmlhttp.responseText; >> xmlhttp.open("GET","../views/edit.php?page="+page+"&action="+action+"&editedpart="+str); xmlhttp.send();
it is not working that is it is not responding.
You could use .attr method:
var title = $(this).closest("span").attr('title');
Your issue is that this doesn’t reference the clicked a element in the showeditpage function.
Altough I dont recommend it, you can fix your issue using the following approach:
However, you should avoid attaching event handlers using attributes and use the approach below:
Put a class on your a tags, like edit for instance ( you could also use any other shared attributes, if any ).
Wait until the document is ready and attach event handlers using jQuery.
Please also note that id should be unique.
var parent = $(this).closest("span[id='editedpart']"); var title = parent.attr('title');
You need to pass the clicked element to the handler method onclick=»showeditpage(this)» .
Also, ID has to be unique in a page, ie only one element should have a given id. In your case I would suggest you to make editedpart as a class instead of id and access the title using var parent = $(this).closest(«.editedpart»); . Also you need to change the ids t_div and edit to classes.
Also you can modify the method to use jQuery
Javascript — How do I select a span content, using jquery, Firstly note that your HTML is invalid. The Jan and 2017 values should be wrapped in the span elements, not set as attributes of it — which itself is invalid.. Secondly it’s better practice to use an unobtrusive event handler over the now outdated on* event attributes. Within that event handler you can use the this …
Jquery parent’s span
How can I output the text to the parent ‘s ? What am i doing wrong? If there are any better solutions than working with spans and .parent() , please let me know.
$('.heroes').hover(function() < var hero = $(this).attr('alt'); $(this).parent('span').text(hero); >, function() < $(this).parent('span').text(""); >);
The span is a sibling of the anchor, not it’s parent.
Indent your HTML, and you see it very easily:
Note: alt isn’t a valid HTML attribute for an anchor.
$(this).closest('div').find('span').text(hero);
is sibling not parent of your links, you can find it based on actual parent.
Jquery get child span element Code Example, jquery get child span element Code Example All Languages >> Javascript >> jquery get child span element “jquery get child span element” Code Answer’s jquery get child div javascript by Mingles444 on Apr 15 2020 Comment 14 xxxxxxxxxx 1 $(this).children(‘div’).show(); Source: stackoverflow.com jquery find
How do I select a span content, using jquery?
I need to get a span text content of ‘Jan’ and ‘2017’ in a onclick function.
I can´t use contains(‘Jan’) or contains(‘2017’) because that values can change at runtime.
I tried the next but no success.
Click me -