javascript - Changing an image source based on an H1 element in the source code or 'location.path'? -
I decided to try a different approach to this problem instead of depending on the string I thought this specific issue To use the function HTML snippet for the image: Any help is welcome and reading, thanks for the cheers. Older Posts: I have a follow up on a recent question but I can not seem to be able to change the code for what I'm seeing. The code is on the following website: I am interested in changing the image source in the code below. However, the new image source has to be determined based on the H-1 element of that webpage. Now I thought it would be useful to use the 'Dictionary List' like the following: Thanks for taking the time to read this, Cheers! EDIT: Here is a piece of code What I was trying to do but I guess it requires more information to actually work. Some examples of this list are: This is a list for which I must manually add each instance of a specific H-1 string page. I give the following suggestions: . In the demo I set the The above change, in a little ( . Any other edits, again to add a default option, within . location.path , the album will be more efficient to determine the source of the cover. Even I still have a lot of things:
& lt; Img src = "http://static.last.fm/flatness/catalogue/noimage/noalbum_g3.png" width = "220" height = "220" square = "album-cover" /> I have a piece of javascript:
var albumCover = document.getElementsByClassName (album-cover) // Album cover var currentLink = Location. Pathname var dictionary = {// location.pathname: image source for albumCover '/ music / King + Crimson / Red': 'http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/ RED.JPG ',' / Music / King + Crimson / Discipline ':' http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/Discipline.jpg '} Now it is a piece of code that is incomplete:
if (currentLink === "// part of the dictionary") {albumCover.src = '' second dictionary Part;}; other{};
& lt; Div class = "g3 album-cover-wrapper album-cover-wrapper-no-cover" & gt; & Lt; Img src = "http://static.last.fm/flatness/catalogue/noimage/noalbum_g3.png" width = "220" height = "220" square = "album-wrapper" /> & Lt; Section square = "Remove add-top-margin-down-margin" & gt; & Lt; Div class = "g4" & gt; & Lt; / Div & gt; & Lt; / Section & gt; & Lt; / Div & gt;
If the string in H1 is 'discipline' { Img.src = "Newsource.jpg '}}
var map = {' Lal ':' O my god! ',' Blue ':' blue? Actually..?' }; Function effect image (source, map) {if (Source!! Map) {return false; } And {var text = source.textContent || Source.innerText; (Different words in the map) {if (map.hasOwnProperty (word) & text.indexOf (word)! == -1) {return map [word]; }}}} // In real life, with an image use: // imageNode.src = effect image (document.getElementsByTagName ('h1') [0], map); Document.getElementById ('test'). Title = effect image (document.getElementsByTagName ('h1') [0], map); One ????
a element of a
a element, but, exactly, as mentioned in the comment, only one image node has
src attribute.
else {...}
Var text = (source.textContent || source.innerText) .toLowerCase (); (Var word in map) {if (Map.hasOwnProperty (word) & amp; text.indexOf (word.toLowerCase ())! == -1) Map of return [word];}}
else {...} if there is no word match:
Comments
Post a Comment