meetdilip
Well-Known Coder
The below code is from an SVG symbol file. It now has <title> which was not there before. I manually added it by referring to " class ". In this case, it is GBP. The title helps us search inside the SVG sprite/symbol file. I have a file with around 1300 + SVG symbols. This means there are 1300 icons without a title but has the info as " class " for each of them.
Is it possible to fetch the info from " class " and add a <title></title> for each icon ?
[CODE lang="xml" title="SVG Symbol"]<symbol
id="symbol16060"
width="16"
height="16"
fill="currentColor"
class="bi bi-currency-pound"
viewBox="0 0 16 16">
<title id="pound gbp">GBP Currency Pound</title>
<path
d="M4 8.585h1.969c.115.465.186.939.186 1.43 0 1.385-.736 2.496-2.075 2.771V14H12v-1.24H6.492v-.129c.825-.525 1.135-1.446 1.135-2.694 0-.465-.07-.913-.168-1.352h3.29v-.972H7.22c-.186-.723-.372-1.455-.372-2.247 0-1.274 1.047-2.066 2.58-2.066a5.32 5.32 0 0 1 2.103.465V2.456A5.629 5.629 0 0 0 9.348 2C6.865 2 5.322 3.291 5.322 5.366c0 .775.195 1.515.399 2.247H4v.972z"
id="path1872-3" />
</symbol>[/CODE]
Can this code help ? If no, it would be nice to have some help. Thanks
[CODE lang="javascript" title="class to title"]
var className = document.getElementsByTagName('symbol')[0].getAttribute('class')
document.getElementsByTagName('symbol')[0].setAttribute('Title', className)
console.log(document.getElementsByTagName('svg')[0])[/CODE]
Is it possible to fetch the info from " class " and add a <title></title> for each icon ?
[CODE lang="xml" title="SVG Symbol"]<symbol
id="symbol16060"
width="16"
height="16"
fill="currentColor"
class="bi bi-currency-pound"
viewBox="0 0 16 16">
<title id="pound gbp">GBP Currency Pound</title>
<path
d="M4 8.585h1.969c.115.465.186.939.186 1.43 0 1.385-.736 2.496-2.075 2.771V14H12v-1.24H6.492v-.129c.825-.525 1.135-1.446 1.135-2.694 0-.465-.07-.913-.168-1.352h3.29v-.972H7.22c-.186-.723-.372-1.455-.372-2.247 0-1.274 1.047-2.066 2.58-2.066a5.32 5.32 0 0 1 2.103.465V2.456A5.629 5.629 0 0 0 9.348 2C6.865 2 5.322 3.291 5.322 5.366c0 .775.195 1.515.399 2.247H4v.972z"
id="path1872-3" />
</symbol>[/CODE]
Can this code help ? If no, it would be nice to have some help. Thanks
[CODE lang="javascript" title="class to title"]
var className = document.getElementsByTagName('symbol')[0].getAttribute('class')
document.getElementsByTagName('symbol')[0].setAttribute('Title', className)
console.log(document.getElementsByTagName('svg')[0])[/CODE]