1

I have a promoted links webpart that I need to display only if a particular text string is displayed in another webpart on the same page. I can successfully capture the text string to a variable but my links webpart isn't being hidden.

Here is my code so far:

<script type="text/javascript">
var ProjectPhase = document.querySelector("table[summary='Project Info Log']").innerText.match(/Phase [1-9]/g)[0]

if (ProjectPhase == 'Phase 1')
{document.getElementById("MSOZoneCell_WebPartWPQ6").style.display = 'none'}

</script>
1
  • Try adding debugger in your code. Are you getting 'Phase 1' value in ProjectPhase variable? Aug 5, 2019 at 12:54

2 Answers 2

1

A few things to check...

The web part is still #6 on the page. ("MSOZoneCell_WebPartWPQ6")

What happens if you type "document.getElementById("MSOZoneCell_WebPartWPQ6").style.display = 'none'" into the browser's Console?

The Summary text contains more than the text you are testing for. Extra spaces, the list's title, etc. summary='Project Info Log' Change to this to a "contains" test.

You regular expression will also match "Phase 11"

0

The following code for your reference,add the code into a script editor web part in site page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var projectPhase=$("table[summary='Project Info Log']").text();
    if(projectPhase.indexOf("Phase 1")!=-1){
        $("#MSOZoneCell_WebPartWPQ6").hide();
    }
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.