Issue
0
`vectorizer = TfidfVectorizer(analyzer='word',norm=None, use_idf=True,smooth_idf=True) tfIdfMat = vectorizer.fit_transform(df['Description']) feature_names = sorted(vectorizer.get_feature_names())
docList=['df.Description'] #skDocsTfIdfdf = pd.DataFrame(tfIdfMat.todense(),index=sorted(docList), columns=feature_names) #print(skDocsTfIdfdf)
for col in tfIdfMat.nonzero()[1]: print (feature_names[col], '-' , tfIdfMat[0, col])`
Solution
Welcome. Into the snippet there are some little mistakes:
- The html for the button lacks of its own id that you are using in the js to get the element and to add the event listener to it;
- The javascript line you use to add the event uses onclick event, this doesn't work because with addEventListener, you have to use just the event without the on part that is needed if you use the inline version of the event, into the html. So basically will be used just click, not onclick;
- Adding the event listener don't use the ( ) part of the function that you are adding, that basically makes it execute immediately at the moment the event listener is added to the html element: use just its name so just myFunction;
- Also because we are adding the event listener by js we don't need to use the onclick='myFunction()' part into the html: we use one or the other no need to use both. Also the addEventListener way is usually the preferred way to go instead the inline version onclick='myFunction()'. In fact, the addEventListener way, keeps the html code cleaner and allows to add multiple events of the same type. But with the onclick='myFunction()' way you can only add one event inline.
- One more suggestion would be to use a separate css instead of inline style.
Now let's see the corrections in action:
document.getElementById("myBtn").addEventListener('click', myFunction);
function myFunction() {
let divElStyle = document.getElementById("myDIV").style;
if (divElStyle.display === "none") {
divElStyle.display = "block";
} else {
divElStyle.display = "none";
}
}
<button id="myBtn">Toggle</button>
<div id="myDIV" class="" role="status" style="display:none;" >
<h4 class="text-info">Loading...</span>
</div>
Answered By - willy wonka
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.