Get span title javascript

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)» .

Читайте также:  Готовый стиль css html

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

-

I have used this function:

As per statement get a span text content of ‘Jan’ and ‘2017’ I am assuming HTML content is

You need to use .text() . No need of using .filter()

var smonth=$("span.spanmonth").text(); var syear=$("span.spanyear").text(); alert(smonth+'-'+ syear); 

I would recommend you to use unobtrusive event handler as @Rory McCrossan suggested.

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.

Читайте также:  Img tag class html

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 keyword to reference the element that raised the event and traverse the DOM to find the span you require. In this case, closest() and find() would suit your needs. Try this:

Note: Your html is invalid as you have ‘Jan’ between the < and >tag instead of text within the span.

In any case, you can try the filter -contains’: $( «span.spanmonth»).filter(«:contains(‘2017’)» );

Javascript — Find span with specific class after input with, Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand ; Advertising Reach developers & technologists worldwide; About the company

Источник

jQuery get the span title for each language and insert in a new span

The following tutorial shows you how to do «jQuery get the span title for each language and insert in a new span».

The result is illustrated in the iframe.

You can check the full source code and open it in another tab using the links.

Javascript Source Code

The Javascript source code to do «jQuery get the span title for each language and insert in a new span» is

$('.Language').each(function () < var txt = $(this).attr('title'); $(this).append("" + txt + ""); >);
html> head> title>get span title and store it for re-using it meta name="viewport" content="width=device-width, initial-scale=1"> script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js" > style id="compiled-css" type="text/css"> span.Language border: 1px solid;> !-- w w w . d e m o 2 s . co m -->   body> div id="languageswitch"> div >"language-object"> span >"Language selected" title="English (United States)">  span >"Language" title="Nederlands (Nederland)"> a href="http://mylocalwebsite.nl/nl-nl/">     script type='text/javascript'> $('.Language').each(function () < var txt = $(this).attr('title'); $(this).append("" + txt + ""); >);   

  • jQuery Get span title
  • jQuery Get span title (Demo 2)
  • jQuery Get the offset of a span’s startpoint
  • jQuery get the span title for each language and insert in a new span
  • jQuery get the span title for each language and insert in a new span (Demo 2)
  • jQuery heights of spans
  • jQuery the id inside a inside a

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

jQuery get the span title for each language and insert in a new span (Demo 2)

The following tutorial shows you how to do «jQuery get the span title for each language and insert in a new span (Demo 2)».

The result is illustrated in the iframe.

You can check the full source code and open it in another tab using the links.

Javascript Source Code

The Javascript source code to do «jQuery get the span title for each language and insert in a new span (Demo 2)» is

$('.Language').each(function () < var txt= "" + $(this).attr('title') + "", link = $('a', this); if(link.length) < link.append(txt); >else < $(this).append(txt); >>);
html> head> title>get span title and store it for re-using it meta name="viewport" content="width=device-width, initial-scale=1"> script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js" > style id="compiled-css" type="text/css"> span.Language border: 1px solid;> !-- w w w . d e m o 2 s . c o m-->   body> div id="languageswitch"> div >"language-object"> span >"Language selected" title="English (United States)">  span >"Language" title="Nederlands (Nederland)"> a href="http://mylocalwebsite.nl/nl-nl/">     script type='text/javascript'> $('.Language').each(function () < var txt= "" + $(this).attr('title') + "", link = $('a', this); if(link.length)< link.append(txt); > else < $(this).append(txt); >>);   

  • jQuery Get span title (Demo 2)
  • jQuery Get the offset of a span’s startpoint
  • jQuery get the span title for each language and insert in a new span
  • jQuery get the span title for each language and insert in a new span (Demo 2)
  • jQuery heights of spans
  • jQuery the id inside a inside a
  • jQuery highlight a span by specific time(with Jquery):

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

jQuery Get span title (Demo 2)

The following tutorial shows you how to do «jQuery Get span title (Demo 2)».

The result is illustrated in the iframe.

You can check the full source code and open it in another tab using the links.

Javascript Source Code

The Javascript source code to do «jQuery Get span title (Demo 2)» is

console.log( $('div#header_customerid_d').find("span").first().attr("title") );
html> head> meta name="viewport" content="width=device-width, initial-scale=1"> script type="text/javascript" src="https://code.jquery.com/jquery-1.6.js" > !-- w w w . d e m o 2 s . co m--> body> div id="header_customerid_d"> div> span title="This is my span">    script type='text/javascript'> console.log( $('div#header_customerid_d').find("span").first().attr("title") );   

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

Оцените статью